Combinator Question

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
suDiego
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Sep 11, 2024 8:14 am
Contact:

Combinator Question

Post by suDiego »

Hey all,

I've a question, which I already tried to solve by myself with all those wikis. But I can't handle this, without help:

I supply my outposts with weapon-trainstations. And what I want to do is something like:

If artillery-ammo OR green-ammo is below 5 (in those chests), then activate trainstation. So Train is comming, when artillery or green-ammo is below 5.
You can see my try here:
Of course, the red wire down goes to the trainstation.

The trainstation is set to - activate if W is below 5. But as I can see in provided signals, this setup simply sum artillery + green ammo.

Do you have any ideas for me?
I'd appreciate a lot.

Kind regards,
suDiego

*as newbie I can't upload pngs?
here is imgur: https://imgur.com/a/HKTzQ0b
Attachments
Screenshot 2024-09-11 100923.png
Screenshot 2024-09-11 100923.png (1.45 MiB) Viewed 274 times

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3705
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Combinator Question

Post by DaveMcW »

This can be solved with two decider combinators.

If artillery-ammo < 5, output W=1.

If green-ammo < 5, output W=1.

Then the train station activates on W >= 1.

Tertius
Filter Inserter
Filter Inserter
Posts: 802
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Combinator Question

Post by Tertius »

Your understanding of the circuit network isn't complete yet. It's more direct than you think, more basic, and you misunderstand what an operation is. Let me explain:
You want:
"if this"
OR
"if that"
then
"something"

You want a logical combination of two comparisons. A logical OR combination. For comparisons, there are decider combinators. They have a condition, and if the condition evaluates to true, the output you define is being output, otherwise nothing is being output.

You used a different kind of OR with the arithmetic combinator. Not suited for what you want. It's a binary OR operation, known from low level assembler programming. It takes the binary representation of the two numbers you supply as operands, perform a binary OR with them, then outputs the result. A binary OR compares the bits of each number one by one, and whenever one of the bits of the operands are 1, the result gets a 1 in this bit as well. The result of this operation only has a meaning, if you gave the single bits of the operands some meaning, but not as number as a whole.

Factorio doesn't have an explicit logical OR. Instead, you simulate it. As DaveMcW suggested, perform the 2 comparisons with a decider combinator for each and output W=1 if the condition is true. Now you add both W. This way you count the amount of matching W. If W is 0, no comparisons matched. If W=1, one comparison matched (and the other not), and if W=2, both comparisons matched. You want to do something if at least one matched, so use W>=1 condition for the combined result.
In other circumstances, for a different use case, you might want both conditions be true (a logical AND). In this case, check for W=2.

Optimization 1:
It may be we can optimize this approach. There is the ANYTHING operator in the decider combinator (the green *). If used as operand, all input signals are checked. If you check for ANYTHING < 5, this condition is true, if at least one of the signals are < 5. You save 1 combinator. However, this will only work if there are no other input signals that might be < 5 and invalidate the check. If there is a 3rd signal on the wire, the check is performed for that as well, and you might not want to check it.

Optimization 2:
You might want to check for different values. For example, you might want to get a train if artillery shells < 5, green ammo < 50 and repair packs < 100 (a third item). You might want even more items to check. We can do this with the help of a single constant combinator and a single decider combinator.
First, wire all chests with your items and make it so that the amount of all items you're interested in are on one wire. Take the constant combinator and add all the signals, i. e. artillery shells, green ammo, repair packs. Give them the negative value of the threshold you want, i. e. artillery shells=-5, green ammo=-50, repair packs=-100. Wire both to the decider combinator, so both wires get added. This way the amount you want (the values from the constant combinator) are subtracted (because they are negative) from the chests with your supply, so if there are not enough items of one kind, its value becomes negative. For item you have enough the value is 0 or positive.
As condition in the decider, set ANYTHING < 0 (the green * wildcard operator), and as output set L=1. Wire this output to the station and enable the train limit feature and use the same signal L (it's the default at the station). This way the station limit is 0 if you have enough of everything (so no train will come) and the limit is 1 if the station needs some item (so some train will come).

suDiego
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Sep 11, 2024 8:14 am
Contact:

Re: Combinator Question

Post by suDiego »

Dear Dave, Dear Tertius,

I appreciate both of your answers a lot. Thanks for the short version and thanks for the long version.
I read about the wildcard before, but didn't understood it well (didn't tried it as well).
But I guess, now I got it and I will give it a try (with the green wildcard :) )

Ok, I have stuff to do. See you :)

suDiego
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Sep 11, 2024 8:14 am
Contact:

Re: Combinator Question

Post by suDiego »

by the way:

you was very right about the 3rd item:

:)
grafik.png
grafik.png (1.13 MiB) Viewed 124 times

Post Reply

Return to “Gameplay Help”