Combinators Resulting in NULL Values

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Fiend
Manual Inserter
Posts: 4
Joined: Tue Sep 08, 2020 7:56 pm
Contact:

Combinators Resulting in NULL Values

Hi,

It seems to be a common issue with combinators that they give a NULL value as a result of their logic, I am building a base strongly dependent on combinators and the problem is sometimes crippling, you get a null value but you can't use a combinator to check if the value is null!! and there doesn't seem to be a reasonable solution for it in game.

astroshak
Filter Inserter
Posts: 287
Joined: Thu May 10, 2018 9:59 am
Contact:

Re: Combinators Resulting in NULL Values

I think the key is to approach it the opposite way.

Make the Factory do something when there is a non-zero result, rather than when there is a zero result.

Just as an example, the use of a negative Constant Combinator added to the (positive, by default) contents of some chests to determine when to turn a Station on (Anything < 0 ... or Anything < -50 ... etc.).

It might require you to rethink your circuit logic a bit, but it works to avoid the 0 = NULL issue.

mmmPI
Filter Inserter
Posts: 501
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Combinators Resulting in NULL Values

Fiend wrote:
Tue Sep 08, 2020 7:59 pm
you get a null value but you can't use a combinator to check if the value is null!! and there doesn't seem to be a reasonable solution for it in game.
can't you use decider combinator, with condition set as "everything = 0" => "output 1 red signal " ? for example

Fiend
Manual Inserter
Posts: 4
Joined: Tue Sep 08, 2020 7:56 pm
Contact:

Re: Combinators Resulting in NULL Values

mmmPI wrote:
Tue Sep 08, 2020 8:19 pm
Fiend wrote:
Tue Sep 08, 2020 7:59 pm
you get a null value but you can't use a combinator to check if the value is null!! and there doesn't seem to be a reasonable solution for it in game.
can't you use decider combinator, with condition set as "everything = 0" => "output 1 red signal " ? for example
Problem is the value is not zero, it's "No Value" the combinator giving the result says nothing in the output, if it were zero I wouldn't have a problem and simply check if the value is zero.

astroshak
Filter Inserter
Posts: 287
Joined: Thu May 10, 2018 9:59 am
Contact:

Re: Combinators Resulting in NULL Values

Fiend wrote:
Tue Sep 08, 2020 8:22 pm
mmmPI wrote:
Tue Sep 08, 2020 8:19 pm
Fiend wrote:
Tue Sep 08, 2020 7:59 pm
you get a null value but you can't use a combinator to check if the value is null!! and there doesn't seem to be a reasonable solution for it in game.
can't you use decider combinator, with condition set as "everything = 0" => "output 1 red signal " ? for example
Problem is the value is not zero, it's "No Value" the combinator giving the result says nothing in the output, if it were zero I wouldn't have a problem and simply check if the value is zero.
Which is why you have the Factory do something based on a non-zero result, rather than a zero result.

Fiend
Manual Inserter
Posts: 4
Joined: Tue Sep 08, 2020 7:56 pm
Contact:

Re: Combinators Resulting in NULL Values

astroshak wrote:
Tue Sep 08, 2020 8:15 pm
I think the key is to approach it the opposite way.

Make the Factory do something when there is a non-zero result, rather than when there is a zero result.

Just as an example, the use of a negative Constant Combinator added to the (positive, by default) contents of some chests to determine when to turn a Station on (Anything < 0 ... or Anything < -50 ... etc.).

It might require you to rethink your circuit logic a bit, but it works to avoid the 0 = NULL issue.

The thing is that the combinator gets 2 signals from the network, one says 10, the other says -10, the result of those two is zero but the combinator returns the value of Null, if I go with teh combinator approach I'd have to use two constant combinators because in my case a positive value and a negative value can result in a different behavior downstream.

The Null behavior is completely unnecessary because you can't check for a null value anyway, it's very obviously a bug.

Squelch
Fast Inserter
Posts: 227
Joined: Sat Apr 23, 2016 5:31 pm
Contact:

Re: Combinators Resulting in NULL Values

It is by design. A zero value is equal to no signal. It has been discussed at length in the past. Zero = Null is quite common in some programming languages, so some reverse logic in your algorithm needs to be applied as already suggested.

If your two signals result in zero, you can use a Decider Combinator with the condition Everything = 0 and output a different signal with a non zero value to indicate the zero result. If that's what you need.

As for needing those two inputs further down the line, it is possible to isolate them from the wire by passing them through an Arithmetic Combinator on each signal with a condition of signal + 0. These will need to be connected before the Decider Combinator, or at the source of the signals.

You don't say specifically whether your signals are on individual Red and Green wires, but when connected to a combinator, all values for [the same signal] are summed in the same way as a single signal wire.

[Edit for clarity]

astroshak
Filter Inserter
Posts: 287
Joined: Thu May 10, 2018 9:59 am
Contact:

Re: Combinators Resulting in NULL Values

Fiend wrote:
Tue Sep 08, 2020 8:31 pm
astroshak wrote:
Tue Sep 08, 2020 8:15 pm
I think the key is to approach it the opposite way.

Make the Factory do something when there is a non-zero result, rather than when there is a zero result.

Just as an example, the use of a negative Constant Combinator added to the (positive, by default) contents of some chests to determine when to turn a Station on (Anything < 0 ... or Anything < -50 ... etc.).

It might require you to rethink your circuit logic a bit, but it works to avoid the 0 = NULL issue.

The thing is that the combinator gets 2 signals from the network, one says 10, the other says -10, the result of those two is zero but the combinator returns the value of Null, if I go with teh combinator approach I'd have to use two constant combinators because in my case a positive value and a negative value can result in a different behavior downstream.
As I said, the trick is to make the system do something on a non-zero result. Set things up such that there is nothing for the system to do with a zero result. Its not always easy, we all understand that ... but its what you need to figure out to get the desired result you seek.

Fiend
Manual Inserter
Posts: 4
Joined: Tue Sep 08, 2020 7:56 pm
Contact:

Re: Combinators Resulting in NULL Values

Squelch wrote:
Tue Sep 08, 2020 8:53 pm
If your two signals result in zero, you can use a Decider Combinator with the condition Everything = 0 and output a different signal with a non zero value to indicate the zero result. If that's what you need.

[Edit for clarity]
But Null does not equal Zero, that's what I meant by "you can't check if the signal is null" if I use you logic the combinator would return no value because its condition has failed.

Khagan
Long Handed Inserter
Posts: 52
Joined: Mon Mar 25, 2019 9:40 pm
Contact:

Re: Combinators Resulting in NULL Values

Fiend wrote:
Tue Sep 08, 2020 9:28 pm
Squelch wrote:
Tue Sep 08, 2020 8:53 pm
If your two signals result in zero, you can use a Decider Combinator with the condition Everything = 0 and output a different signal with a non zero value to indicate the zero result. If that's what you need.
But Null does not equal Zero, that's what I meant by "you can't check if the signal is null" if I use you logic the combinator would return no value because its condition has failed.
Any test against "Everything" passes if all signals are null. Including the test for "Everything = 0".

Squelch
Fast Inserter
Posts: 227
Joined: Sat Apr 23, 2016 5:31 pm
Contact:

Re: Combinators Resulting in NULL Values

Fiend wrote:
Tue Sep 08, 2020 9:28 pm
But Null does not equal Zero, that's what I meant by "you can't check if the signal is null" if I use you logic the combinator would return no value because its condition has failed.
The "Everything" input is a special case, and does return true when there is no input.
See the tooltip:
Everything Tip.PNG (111.29 KiB) Viewed 202 times

Here is a little circuit that I made to indicate via the lamp on the left when the Red and Green wires amount to zero. It lights when both Constant Combinators (top) are off, AND when they are both on. In the first instance no input, and in the second, Black signal -10 on Green AND Black signal 10 on Red. The Decider Combinator output on White is true for no input once again.

Everything and Isolation.PNG (1.88 MiB) Viewed 202 times

I have placed two Arithmetic Combinators to isolate the signals, and then added Black 2 via the lower right Constant Combinator. The bottom right lamp has the condition Black = 12. The extra 2 does not propagate back to the original signal on the Red circuit, so therefore is isolated from it.

I have labeled each of the devices with their properties.

Perhaps you could share what your use case is, and someone can give you some hints? It is frustrating, I know, but this is the realm of Nauvis, and our protagonist, The Engineer, uses this same logic in [his/her/insert appropriate identity here] world. It just needs some lateral thinking to get what you need done.

[Edit for correction] I transposed the values for the upper constants in the text.

wisery
Manual Inserter
Posts: 2
Joined: Sat Aug 29, 2020 11:20 pm
Contact:

Re: Combinators Resulting in NULL Values

Oh, this "zero signal is no signal" is so painful for me. I want my supply train to depart from station if one cargo type is fully unloaded by circuit network signal. I just don't get how to do it. My head don't work that way( And there is already nearly ten combinators to call train to station and send it further, when station demands are met.

starlinvf
Long Handed Inserter
Posts: 68
Joined: Sat Dec 14, 2019 6:28 pm
Contact:

Re: Combinators Resulting in NULL Values

wisery wrote:
Sat Sep 12, 2020 11:10 pm
Oh, this "zero signal is no signal" is so painful for me. I want my supply train to depart from station if one cargo type is fully unloaded by circuit network signal. I just don't get how to do it. My head don't work that way( And there is already nearly ten combinators to call train to station and send it further, when station demands are met.
Are you setting that parameter on the train schedule, or using enable/disable at the station?

wisery
Manual Inserter
Posts: 2
Joined: Sat Aug 29, 2020 11:20 pm
Contact:

Re: Combinators Resulting in NULL Values

starlinvf wrote:
Sat Sep 12, 2020 11:40 pm
wisery wrote:
Sat Sep 12, 2020 11:10 pm
Oh, this "zero signal is no signal" is so painful for me. I want my supply train to depart from station if one cargo type is fully unloaded by circuit network signal. I just don't get how to do it. My head don't work that way( And there is already nearly ten combinators to call train to station and send it further, when station demands are met.
Are you setting that parameter on the train schedule, or using enable/disable at the station?
Schedule to departure, enable/disable to call supply train.

disentius
Filter Inserter
Posts: 454
Joined: Fri May 12, 2017 3:17 pm
Contact:

Re: Combinators Resulting in NULL Values

You can do something like this:

check two conditions:
- Train at station and the resource you want to check = 0