Circuits: How does lamp choose color with multiple signals?
Circuits: How does lamp choose color with multiple signals?
I wanted to make a simple indicator light to show the level of material in a chest or tank. I see that the tooltip for the lamp's color option says "if multiple color signals are input, only one will be used". But which one?? I assumed it would be the one with the highest value, so I set up my combinators like so:
Decider: IF crude-oil > 2400 THEN Blue
Decider: IF crude-oil > 1500 THEN Green
Decider: IF crude-oil > 500 THEN Yellow
Decider: IF crude-oil < 501 THEN Red
Each combinator had its input attached to the tank and its output attached to the light. I also connected a constant combinator to the deciders' inputs with the following values:
-Red=1
-Yellow=2
-Green=3
-Blue=4
So now if my tank level is at 1800, the circuit network correctly sends both "Yellow=2" and "Green=3" signals to the light. I expected the light to be green because the green signal was higher, but it showed yellow! Is this a bug? How do I fix it?
Decider: IF crude-oil > 2400 THEN Blue
Decider: IF crude-oil > 1500 THEN Green
Decider: IF crude-oil > 500 THEN Yellow
Decider: IF crude-oil < 501 THEN Red
Each combinator had its input attached to the tank and its output attached to the light. I also connected a constant combinator to the deciders' inputs with the following values:
-Red=1
-Yellow=2
-Green=3
-Blue=4
So now if my tank level is at 1800, the circuit network correctly sends both "Yellow=2" and "Green=3" signals to the light. I expected the light to be green because the green signal was higher, but it showed yellow! Is this a bug? How do I fix it?
Re: Circuits: How does lamp choose color with multiple signals?
I made a working version of my machine, but it took twice as many combinators because I had to make sure only one color signal at a time ever reached the lamp.
I still think the lamps should use whatever color signal has the highest value.
I still think the lamps should use whatever color signal has the highest value.
Re: Circuits: How does lamp choose color with multiple signals?
Maybe this will help you:
You need only 2 combinators to color your display in all colors.
You need only 2 combinators to color your display in all colors.
Blueprint, KBlueprints mod
Re: Circuits: How does lamp choose color with multiple signals?
Surely it's impossible to do this with only two combinators... At the very least I would need one for every threshold I want to create for when the color changes...?
What do I do with this code?
Surely if there's only two combinators you could describe for me what they're set to?
What do I do with this code?
Surely if there's only two combinators you could describe for me what they're set to?
Re: Circuits: How does lamp choose color with multiple signals?
Impossible... many things in Factorio seems to be impossible at the first sight.xyzyxx wrote:Surely it's impossible to do this with only two combinators... At the very least I would need one for every threshold I want to create for when the color changes...?
First of all, you should install this mod: KBlueprints
Then you should copy-paste that blueprint string in it and create a new blueprint.
That's all
By the way, blueprint string is a common way to share your builds with other players.
Re: Circuits: How does lamp choose color with multiple signals?
Ok, I'm looking at the machine now, but I don't understand it.
How does it work to use * (Each) as an output? I have not messed with * yet.
And what does the black signal do?
I don't want to copy paste someone elses design without understanding how it works.
How does it work to use * (Each) as an output? I have not messed with * yet.
And what does the black signal do?
I don't want to copy paste someone elses design without understanding how it works.
Re: Circuits: How does lamp choose color with multiple signals?
"Each > plate, output Black 1": first combinator compares each input signal with plate signal, and sends "1 Black" for each successful comparison.
Input: plate - 234. Thresholds: A = 100, B = 200, C = 300, D = 400.
Unfolding each statement:
- A > plate? => 100 > 234? => false, output: nothing
- B > plate? => 200 > 234? => false, output: nothing
- C > plate? => 300 > 234? => true, output: 1 Black
- D > plate? => 400 > 234? => true, output: 1 Black
- plate > plate? => 234 > 234? => false, output: nothing
Total output: 2 Black.
"Each = Black, output Each": second combinator is used to decode Black value into color signal.
Input: input: 4 Red, 3 Yellow, 2 Green, 1 Blue (this is just an example, blueprint uses 5 colors), and 2 Black from first combinator
Unfolding each statement:
- Red == Black? => 4 == 2? => false, output: nothing
- Yellow == Black? => 3 == 2? => false, output: nothing
- Green == Black? => 2 == 2? => true, output: 2 Green
- Blue == Black? => 1 == 2? => false, output: nothing
- Black == Black? => 2 == 2? => true, output: 2 Black
Total output: 2 Green and 2 Black
Black signal is ignored because it has lower ID, so we have green lamp.
Input: plate - 234. Thresholds: A = 100, B = 200, C = 300, D = 400.
Unfolding each statement:
- A > plate? => 100 > 234? => false, output: nothing
- B > plate? => 200 > 234? => false, output: nothing
- C > plate? => 300 > 234? => true, output: 1 Black
- D > plate? => 400 > 234? => true, output: 1 Black
- plate > plate? => 234 > 234? => false, output: nothing
Total output: 2 Black.
"Each = Black, output Each": second combinator is used to decode Black value into color signal.
Input: input: 4 Red, 3 Yellow, 2 Green, 1 Blue (this is just an example, blueprint uses 5 colors), and 2 Black from first combinator
Unfolding each statement:
- Red == Black? => 4 == 2? => false, output: nothing
- Yellow == Black? => 3 == 2? => false, output: nothing
- Green == Black? => 2 == 2? => true, output: 2 Green
- Blue == Black? => 1 == 2? => false, output: nothing
- Black == Black? => 2 == 2? => true, output: 2 Black
Total output: 2 Green and 2 Black
Black signal is ignored because it has lower ID, so we have green lamp.
Re: Circuits: How does lamp choose color with multiple signals?
What is "lower ID"? Is this what determines what color is used when multiple colors are sent to the lamp?
Strange. Don't you agree that it should use the value of the signal instead?
Strange. Don't you agree that it should use the value of the signal instead?
Re: Circuits: How does lamp choose color with multiple signals?
Okay, replace Black signal everywhere with "Z signal" and lamps will recieve only one color signal.xyzyxx wrote:What is "lower ID"? Is this what determines what color is used when multiple colors are sent to the lamp?
Strange. Don't you agree that it should use the value of the signal instead?
This is just a my habit... I am using color signals as internal signals in various builds, and this build is not an exception.
But you are right, black is not a very good choice for this build .
Last edited by XKnight on Tue Sep 06, 2016 6:18 pm, edited 1 time in total.
Re: Circuits: How does lamp choose color with multiple signals?
I still think that if a light recieves a Blue 4 and a Green 3 it should use Blue because 4 is higher.
Re: Circuits: How does lamp choose color with multiple signals?
You didn't actually answer either of my two questions.Okay, replace Black signal everywhere with "Z signal" and lamps will recieve only one color signal.
This is just a my habit... I am using color signals as internal signals in various builds, and this build is not an exception.
But you are right, black is not a very good choice for this build .
Re: Circuits: How does lamp choose color with multiple signals?
Signal ID. Knowledge about ID existence comes from fact that some entities (lamps with custom color, filtered inserters, requester chests, "Anything" mode in 0.12, and so on) prefer one signal to another and this preference is deterministic. Also, relation between different signals is transitive, this means if some entity prefer signal A to signal B and signal B to signal C, it will prefer signal A to signal C.xyzyxx wrote:What is "lower ID"? Is this what determines what color is used when multiple colors are sent to the lamp?
In other words, we can assign some unique integer number to each signal, and say that "signal A has lower ID than signal B" if every entity prefers signal B to signal A. From player point of view this is the fact, maybe moders and devs can give more detailed explanation, but even this explanation is enough to understand what happens here.
Wooden chest has the highest ID, black signal the lowest.
Also, ID decreases from left to right, from top to bottom, from the first tab to the last tab, for example:
wooden chest > storage tank > stone brick > landfill > iron axe > productivity module 3 > lubricant > signal 0 > red signal > black signal.
Actually, I might be wrong, maybe in reality wooden chest has the lowest ID and each entity prefer signal with lower ID.
Anyway, this is just a matter of representation and preference sequence still will be the same.
Maybe yes and maybe no. Sometimes this is very useful, and sometimes you have to find dirty solution around this.xyzyxx wrote:Strange. Don't you agree that it should use the value of the signal instead?
But in my opinion, relying on this thing already indicates that something bad happens there.
As far as I know there is some suggestion to replace current behaviour with value-based, details you may find in "Ideas and Suggestions" forum.
Re: Circuits: How does lamp choose color with multiple signals?
I have located the thread you mentioned and even added an additional suggestion about changing the order of the ID's -
viewtopic.php?f=6&t=28173&p=203543#p203543
Should I post that as a separate thread in the suggestions board?
viewtopic.php?f=6&t=28173&p=203543#p203543
Should I post that as a separate thread in the suggestions board?
Re: Circuits: How does lamp choose color with multiple signals?
Consider the following.
Each coloured square is a signal with value of 1. Each lamp is set to any=2. The top two circuits display correct colour. The bottom does not.
I realize there's been a fair amount of discussion about lamp colour preferences etc, and I can buy the argument that current preferences (in the absence of other criteria) are not optimal. However, changing colour preference will only fix part of the problem.
The problem is that there is no way of specifying activation condition. Using "any"will deliver all colours (provided at least one signal satisfies the condition) at which point the lamp will pick and choose.
One solution to this is to force the lamp to activate on signal that satisfies 'any'. The other would be to introduce 'each' selector.
Each coloured square is a signal with value of 1. Each lamp is set to any=2. The top two circuits display correct colour. The bottom does not.
I realize there's been a fair amount of discussion about lamp colour preferences etc, and I can buy the argument that current preferences (in the absence of other criteria) are not optimal. However, changing colour preference will only fix part of the problem.
The problem is that there is no way of specifying activation condition. Using "any"will deliver all colours (provided at least one signal satisfies the condition) at which point the lamp will pick and choose.
One solution to this is to force the lamp to activate on signal that satisfies 'any'. The other would be to introduce 'each' selector.
Re: Circuits: How does lamp choose color with multiple signals?
You have to install the correct mod: https://mods.factorio.com/mod/KBlueprints
Hint: You also have to install the correct factorio version (0.15).
Hint: You also have to install the correct factorio version (0.15).
Re: Circuits: How does lamp choose color with multiple signals?
You misunderstand highest.
the colors have a hierarchy. see wiki here: https://wiki.factorio.com/Lamp
This means that if a lamp gets a red and a green signal, no matter the value, it will display the red signal, as this is above green in the list. the biggest complication in your setup is that yellow has a lower priority than green and blue.
If you follow the color hierarchy, the circuit becomes simple with the integer overflow trick (learned that one from DaveMcW:))
Overflow trick: every value above 2^31 gets flipped to negative. in mij example i used the following values for the colors in the combinator:
Red: 2^31 - 100
Yellow: 2^31 - 200
Magenta: 2^31 - 300
Cyan: 2^31 - 400
the colors have a hierarchy. see wiki here: https://wiki.factorio.com/Lamp
This means that if a lamp gets a red and a green signal, no matter the value, it will display the red signal, as this is above green in the list. the biggest complication in your setup is that yellow has a lower priority than green and blue.
If you follow the color hierarchy, the circuit becomes simple with the integer overflow trick (learned that one from DaveMcW:))
Overflow trick: every value above 2^31 gets flipped to negative. in mij example i used the following values for the colors in the combinator:
Red: 2^31 - 100
Yellow: 2^31 - 200
Magenta: 2^31 - 300
Cyan: 2^31 - 400
Re: Circuits: How does lamp choose color with multiple signals?
I had a three combinator / three constants solution but I really like XKnight's approach, which shaves one of each off and requires less configuration.
The concept is: You divide your incoming signal into segements, one per colour, and count how many of those segments are used. That's the purpose of the first combinator, which is fed thresholds for each segment from the constant combinator.
That segment count is then fed to the second combinator, which determines what colour should be used if that many segments are in use.
Effectively, it tests if the colour signals it is being fed from the constant combinator equal the segment count it was fed from the previous calculation. As long as the values of the colour signals are all unique (e.g. red and green aren't both assigned 2) and cover the full set of possible segment counts (e.g. if you have three divisions, you have Red = 1, Yellow = 2, Green = 3), then one, and only one, of those colour values is passed through to the lights. Whether the lights are lit or not is controlled from the original measurement channel.
(This does mean that the colour changes will be two ticks behind the quantity changes. This doesn't strike me as an especial concern.)
The concept is: You divide your incoming signal into segements, one per colour, and count how many of those segments are used. That's the purpose of the first combinator, which is fed thresholds for each segment from the constant combinator.
That segment count is then fed to the second combinator, which determines what colour should be used if that many segments are in use.
Effectively, it tests if the colour signals it is being fed from the constant combinator equal the segment count it was fed from the previous calculation. As long as the values of the colour signals are all unique (e.g. red and green aren't both assigned 2) and cover the full set of possible segment counts (e.g. if you have three divisions, you have Red = 1, Yellow = 2, Green = 3), then one, and only one, of those colour values is passed through to the lights. Whether the lights are lit or not is controlled from the original measurement channel.
(This does mean that the colour changes will be two ticks behind the quantity changes. This doesn't strike me as an especial concern.)
Re: Circuits: How does lamp choose color with multiple signals?
I know I'm necro'ing this thread but I ran across it via Google while looking for how to do multi-colored lights and decided to reply for anyone else that stumbles along later.
Recreation:
The original version was heavily tied to iron plates, with each lamp having logic checking their amount. This one swaps that out for the dot signal and converts the input iron plate signal into that so it can be easily adapted. Only have to change 1 arithmetic combinator instead of a decider combinator and 15 lamps.
The crossed-out constant combinator is outputting an iron plate signal for the demo and marks where your input signal goes.
==========================
A version of the above but more easily supporting min/max meter scale:
As with the one above, the crossed-out constant combinator is outputting an iron plate signal for the demo. The constant combinator with the 0/1 signals (the one above the arithmetic combinators) is how you set the min/max. The blueprint uses a min of 0 and a max of 1000. The lamp on the far left only lights when there's <= the minimum and can be safely removed without breaking anything if it's unwanted.
==========================
Explanation of how the original worked:
It has two main parts: The item count logic and the color logic.
The 2 constant combinators next to the 2 decider combinators, and the 2 deciders themselves, are all you really need. The first set of constant+decider converts the item count into a color selector index. The second set of constant+decider does the actual color selecting.
Basically...
... the top constant has 5 signals, each being the cut-off used for each color (like signal 0 is 301, so red is used if the item count is <= 300, etc). It uses the 'each' signal to compare the item count to each of these cut-offs and output a black signal with the value of 1. As a result, it outputs black (3) if the item count is <= 1200.
... the bottom constant has the 5 colors. It uses the black signal to select the color with the 'each' signal.
This makes it rather easy to adapt it to only have 3 colors, or 6, by just changing the cut-offs and color indexes.
My update to it adds an extra step to make the meter more generic, by turning the dot signal into a percentage (using the 0/1 signals) to display rather than hard-set values.
I took the KBlueprint version and based a couple of easier-to-adapt versions on it.
Recreation:
The original version was heavily tied to iron plates, with each lamp having logic checking their amount. This one swaps that out for the dot signal and converts the input iron plate signal into that so it can be easily adapted. Only have to change 1 arithmetic combinator instead of a decider combinator and 15 lamps.
The crossed-out constant combinator is outputting an iron plate signal for the demo and marks where your input signal goes.
==========================
A version of the above but more easily supporting min/max meter scale:
As with the one above, the crossed-out constant combinator is outputting an iron plate signal for the demo. The constant combinator with the 0/1 signals (the one above the arithmetic combinators) is how you set the min/max. The blueprint uses a min of 0 and a max of 1000. The lamp on the far left only lights when there's <= the minimum and can be safely removed without breaking anything if it's unwanted.
==========================
Explanation of how the original worked:
It has two main parts: The item count logic and the color logic.
The 2 constant combinators next to the 2 decider combinators, and the 2 deciders themselves, are all you really need. The first set of constant+decider converts the item count into a color selector index. The second set of constant+decider does the actual color selecting.
Basically...
... the top constant has 5 signals, each being the cut-off used for each color (like signal 0 is 301, so red is used if the item count is <= 300, etc). It uses the 'each' signal to compare the item count to each of these cut-offs and output a black signal with the value of 1. As a result, it outputs black (3) if the item count is <= 1200.
... the bottom constant has the 5 colors. It uses the black signal to select the color with the 'each' signal.
This makes it rather easy to adapt it to only have 3 colors, or 6, by just changing the cut-offs and color indexes.
My update to it adds an extra step to make the meter more generic, by turning the dot signal into a percentage (using the 0/1 signals) to display rather than hard-set values.