Factorio

Factorio

View Stats:
Need help using ONE lamp to output multiple colors
I have a project in mind where lamps will light up in different colors based off of the distance of the train (project 1) or nearest train (project 2).

Edit: I just managed to learn how to use 3 combinators to change the lamp color of one lamp taking advantage of color priorities, but is there a simpler way of changing different colors based off of conditions?

Does anyone have some basic tips, reading, or a blueprint I can use to learn
Last edited by Mist of Majora; Jan 21, 2018 @ 5:35pm
< >
Showing 1-10 of 10 comments
Killcreek2 Jan 22, 2018 @ 12:34am 
There are a few ways, but without understanding / seeing your project it is hard to recommend any specific setups.

Couple of different ideas / approaches:

1> XOR setup ~ send the trigger signals to the inputs of a pair of combis, with both outputs connected to a lamp. Have 1 combi set to "if A > B, output Red" & the other combi set to "if B >= A, output Green". Simple, but not very expandable.
As this only outputs 1 colour at a time, it avoids the colour priority entirely.

2> Use a "lookup table" in a constant combi wired into a decider combi. Have each colour preset in the table using a different signal value, & set the decider to "if Each = <control signal>, output Each" ~ so it will only pass-through colour signals that match the trigger signal value.
(This works best if you keep the colour priority in mind, & can then use ">=" or "=<" in the decider ~ to output multiple colours for later processing.)

3> Using colour signals as part of the circuitry, carrying the data values ~ set the combis up so only the correct (coloured) signal is output based on whichever input conditions / signals you require.
This approach can simplify some contraptions, if you are careful to avoid "signal bleed".
Mist of Majora Jan 22, 2018 @ 9:28am 
First off thank you very much for the replies and I do apologize for not being more specific with my question. I'll do my best to explain the ideal goals of my project, though I do apologize for the giant wall of text in doing so!

There's basically two end goals for me with what I'm trying to accomplish. The first and easiest is to light up the nearby area as far ahead as possible in red by the rails when a train is nearby. Basically, it's a visual warning system. I think I already have a nice simple solution to this using rail/chain signals.

The second goal, which is the problematic one and the main reason for this post, is using a different (and very preferably multiple colors) that follow a train both for looks and as a final visual warning. The first problem with this setup as I see it I need a very responsive 'trigger' as you guys put it and the best idea I've come up with so far is using gates over the tracks as the trigger. I can see turns and train stations being problematic with this methodology, but I can't think of anything better at the moment.

Problem #2 is I'd like to animate the 'wake' of water behind the train as part of its visual animation, but I'm only stating this for the sake of explaining my thought process.

For the sake of sanity in this discussion, I think I can accomplish Goal #2 in it's entirety if I 'simply' ask for the solution to a more basic goal - as the train is moving, how do i set up a parallel set of lamps to the tracks to output green in the first 4 lights in front of the train, and blue in the 4 lights behind it.
Killcreek2 Jan 23, 2018 @ 1:53am 
Ok, that gives a good idea of what you are after, thanks.
(I am assuming a spacing of roughly 1 wagon length between lamps along the track, for the rest of this post.)

Re; Goal #1 (lighting in advance of the train):
Using signals / gates to detect a train is fine. They can be set to output a specific signal, which can be the trigger for a specific lamp further up the track.

Eg: signal at position 1 outputs "A" if a train is in its block, signal at 2 outputs "B", signal 3 ouputs "C", etc.
Lamp at position 5 activates if it sees an "A" signal, lamp at 6 lights up if it sees a "B", & so on.


This would allow a single wire connecting all of the signals and lamps to carry the data channels, & requires only a single constant combi if you want a non-white colour.


Re; Goal #2 (multicolour train echoing). This is much more complicated:
Signal / gate detectors should work fine here too. But I would use a different approach to goal #1, as you would need to include the colour selection data also. Which will require combis, likely 1 per lamp plus a few in the control circuit, possibly more. (Maybe less, if you understand "black magic" combinator use better than I do...)

I can see one method that might work, involving a "step up" counter, to add +1 per detector passed by the train along that section of track.
Using a "bit shifting" combi setup would allow that count to trigger the correct lamps to match the train position, & it should be possible to encode the colour signal data alongside the trigger signal (so you won't need 1 colour picker combi setup, per lamp, just 1 per track section).

It's much like building a scrolling colour display, in how you would need to program the combis & lamps. But instead; using the train position to increment the lamp data, rather than via a clock signal as in most displays.

DaveMcW posted a nice detailed explanation of how he programmed his colour display, which might give you some hints for your goals. Check out how he sends multiple colour signals down the same wire without interference here: https://forums.factorio.com/viewtopic.php?f=193&t=37490
There are some other posts in that "Combinator Contraptions" subforum that may be of help ~ look for "scrolling display" topics.
Mist of Majora Jan 23, 2018 @ 8:53am 
Wow thanks for the detailed post Killcreek:)

I'd rather not space out the lamps at all if possible, but either way, your post has given me some great ideas and insight into lamp setups so thanks very much!! I still need to do some more research on some of the methods you posted like 'bit shifting', but I can already picture a design with the 'step up' counter to trigger a 'wake' in the water behind the train for 5 seconds - and then 'time it out' back to 'off' when it counts to 7 - or something along that line of thinking.

Again thanks again for everyone's help and if I succeed I'll try to find a way to post the train in action as a thank you :)
Killcreek2 Jan 23, 2018 @ 2:52pm 
You are very much welcome. :)

The lamp spacing is kinda arbitrary, each "lamp" could be a block of 7 instead (ie; 1 wagon length+gap). It just makes it a bit easier to plan & test, if you space things out ~ you can always compress the design later.

Had another think about it, & there may be a somewhat simpler method to do the wake effect:
The rail signals can already output different colours to indicate thier status (defaults are: track reserved = yellow, track occupied = red, track clear = green).

So, you could use them to directly control the colour of the wake infront, next to, & behind the train (though, some reassigning would be needed to account for colour priority).

Would need a lot of precise wires though & likely a combi per lamp. eg; from each signal a red wire connecting to a lamp (+combi) further up the track, & green wire connecting to another lamp (+combi) back down the track. Ditto for each signal, connecting to lamps same distance ahead & behind each time.

Should be able to use the native colour signals from the ahead & behind rail signals (via the green & red wires), processed in the combi, to light the lamp with the correct colour.
Mist of Majora Jan 23, 2018 @ 3:54pm 
Man you've got some great ideas :)

I had no idea that Factorio was smart enough to output the native color signals of the rail signals, so I could definitely have some fun with that at some point!

But my big fear in implementing that suggestion is that, at least in my experience, inevitably more rail signals = automated train problems. So massing chain signals along the rails could be very dangerous lol.

Granted, I'm still slowly working on getting a proper handle on the mechanics of color wiring, but after our discussions I'm toying with a mass blueprinted module of (estimating) 10 lights in front and 10 in back that basically cause a ripple effect of a wake when triggered. If duplicated enough it might cause the illusion of that almost 'double wake' you'd normally see behind a boat depending on how fine I can control the speed of the color switching and my art skills lol. In theory if done correctly, it would have the benefit of not only being easily replicated but would be effective regardless of the speed of the train which would be pretty cool.
Last edited by Mist of Majora; Jan 23, 2018 @ 3:54pm
Killcreek2 Jan 23, 2018 @ 4:46pm 
Adding more rail signals (or gates) should not affect the train pathing itself, but unfortunately will cost UPS due to the extra cpu load to process every data change for each lamp, rail signal / gate, & combi.

Using this for a few track sections should be fine, but setting it up to cover a giant network would likely incur a noticable performance drain.
Spacing the triggers apart & using short blocks of lamps instead of each individual lamp being controlled seperately would also help alleviate that cpu load.


Combinators & the circuit network are far more powerful that it may seem at first glance. The amount of data you can fit in a single signal channel is huuuge (each is a 32-bit signed integer!).
My advice is to just get stuck in, experiment and build stuff ~ early contraptions are likely to be inelegant monsters, but later ones can become sleek & smart models of efficiency as you learn new tricks.
Have fun! It sounds like a cool project, & would be nice to see a vid / BP of it in action, once you get it working.
soldier6661111 Jan 23, 2018 @ 5:46pm 
You could do something similar with the programmable speaker for an audio warning.
Mist of Majora Jan 23, 2018 @ 5:55pm 
Thanks Kill - I definitely appreciate all the help you've given! And I didn't even consider the CPU load of mass gates/rail signals. That may kill the practicality of my project right there :( Well I'll still toy with it as a proof of concept at least haha. And ofc, if I get it working I'll do my best to post a vid, and lacking that, maybe the blueprint for the community to use as a thank you for all the dumb questions I've asked leading up to this point :)

And Soldier I could definitely do that and it would take a lot less work! Unfortunately, if I do this setup on a full rail network, at most of the crossings I would need, I'd probably hear that sound non-stop since the train would always be nearby a crossing block (either before or after). Plus I've noticed there's no way to discern where the audio is coming from in game which is another problem. When programmable speakers were first introduced, my friend turned on the default alarm and left for the day, and it took hours before we found it in our megafactory lol.

soldier6661111 Jan 23, 2018 @ 6:04pm 
Odd. I'm trying it in sandbox mode and have the same issue. I don't have global playback checked so it shouldn't be heard all over the map. This is my first semi-success with the circuit network. There are some issues and it may be different in an actual game.
< >
Showing 1-10 of 10 comments
Per page: 1530 50

Date Posted: Jan 21, 2018 @ 4:49pm
Posts: 10