Page 1 of 1

Is there a way to check if two circuit signals are the same?

Posted: Wed May 23, 2018 5:18 am
by fishercat5
I'm attempting to make a needlessly complex train system, and part of it requires being able to tell if two wires are carrying the same signal, or at least being able to tell if they use the same symbol/icon.

For example, I have a red wire carrying the signal A=1, and a green wire carrying the signal B=1. I know how to check that the values are the same, by simply passing them through a combinator to check if A = B. What I need is a way to tell whether the two wires are carrying the same signal. In this case, that would be false, as one is A and one is B.

I know this gets more complex with wires carrying multiple values, but my use case should only ever deal with wires carrying one signal.

Is this at all possible in Factorio?

Re: Is there a way to check if two circuit signals are the same?

Posted: Wed May 23, 2018 5:47 am
by DaveMcW
Put a decider combinator on each network: Each ≠ 0 → Each = 1
Use that as input for a third decider combinator: Each = 2 → S = 1
S will contain the number of matching signals.

There is also a way to test for identical signals (same icon and value).
Use an arithmetic combinator to make network #1 negative: Each * -1 → Each
Feed the arithmetic combinator result and network #2 into a decider combinator: Everything = 0 → S = 1
If you don't want two empty networks to match, use a third decider combinator to test network #2: Anything ≠ 0 → S = 1
Connect the two decider combinator results together, if S = 2 then they are identical.

Re: Is there a way to check if two circuit signals are the same?

Posted: Wed May 23, 2018 5:58 am
by Lav
fishercat5 wrote:Is this at all possible in Factorio?
Easy.

Connect first network to arithmetic combinator A, which is set to Each * 1 = Each. It essentially copies the signals from first network without contaminating it.

Connect second network to arithmetic combinator B, which is set to Each * -1 = Each. This one does the same with second network, but inverts the values.

Connect outputs of both combinators and route them to a decider combinator, which is set to IF Any != 0 THEN 1.

This will check the equality of any signal or any combination of signals in two networks.

Re: Is there a way to check if two circuit signals are the same?

Posted: Wed May 23, 2018 7:50 pm
by ColonelSandersLite
Won't work.

To illustrate the problem -

Imagine a red wire with 1 copper plate and a green wire with 1 iron plate.

Combinator A = 1 Copper Plate.
Combinator B = -1 Iron Plate.
IF Any != 0 THEN 1 outputs 1.

The stated goal is false

Re: Is there a way to check if two circuit signals are the same?

Posted: Wed May 23, 2018 8:03 pm
by ColonelSandersLite
fishercat5 wrote:For example, I have a red wire carrying the signal A=1, and a green wire carrying the signal B=1. I know how to check that the values are the same, by simply passing them through a combinator to check if A = B. What I need is a way to tell whether the two wires are carrying the same signal. In this case, that would be false, as one is A and one is B.

I know this gets more complex with wires carrying multiple values, but my use case should only ever deal with wires carrying one signal.

Is this at all possible in Factorio?
Here's a way. Suppose you want to know if both wires carry a value for A.

Connect the red wire to a decider.
If A != 0 Output 1 Green

Connect the green wire to a decider.
If A != 0 Output 1 Green

Connect both deciders to a third decider.
If Green > 1

If it returns true, both wires have a value for A.



Edit: Some bad info was cut.
Edited again:
I need to stop trying to post accurate information when I should be in bed.

Re: Is there a way to check if two circuit signals are the same?

Posted: Thu May 24, 2018 3:51 am
by Lav
ColonelSandersLite wrote:Won't work.

To illustrate the problem -

Imagine a red wire with 1 copper plate and a green wire with 1 iron plate.

Combinator A = 1 Copper Plate.
Combinator B = -1 Iron Plate.
IF Any != 0 THEN 1 outputs 1.

The stated goal is false
I don't understand you. Output of 1 indicates the network signals are not equal. Which they aren't in your example.

Re: Is there a way to check if two circuit signals are the same?

Posted: Thu May 24, 2018 5:01 am
by ColonelSandersLite
Edit: Oh, I see, let me rephrase.

Try this on for size then.


Imagine. Network A has 1 iron plate. Network b has 1 iron plate and one copper plate.

Since both networks have an iron plate signal, the desired output is true. Your method would return false.


Edit 2:
Another situation that would return undesired results:
Network A has 1 iron plate. Network b has 2 iron plates.

Since both networks have iron plates, the desired output is true. Your method, again, returns false.

Re: Is there a way to check if two circuit signals are the same?

Posted: Thu May 24, 2018 6:06 am
by Lav
ColonelSandersLite wrote:Network A has 1 iron plate. Network b has 1 iron plate and one copper plate.

Since both networks have an iron plate signal, the desired output is true.
Methinks we're solving two very different tasks. Perhaps OP's clarification is necessary for what "the two wires are carrying the same signal" actually means. Full match of all values, or match of any single value among multiples, or match of one specific value. The last option is pretty trivial and can be easily resolved by translating the signal from one resource to another.

Re: Is there a way to check if two circuit signals are the same?

Posted: Thu May 24, 2018 2:04 pm
by disentius
this?
Find duplicates.png
Find duplicates.png (366.62 KiB) Viewed 7690 times
Output: Duplicate signals only
Constant combinators are input simulators, send signals with value 1
If incoming signals are actual amounts, convert them to 1 first.

Re: Is there a way to check if two circuit signals are the same?

Posted: Thu May 24, 2018 9:01 pm
by Hedning1390
disentius wrote:this?
Yes. Check the first reply. It's the same suggestion. I don't know why this topic keeps going when the problem was solved with the first post.

Re: Is there a way to check if two circuit signals are the same?

Posted: Fri May 25, 2018 10:23 am
by disentius
Cranky, aren't we? :twisted:

I put a picture in for clarity, and forgot to mention it was an illustration to the first answer.