Logic network: do one thing when condition matches and do another thing when it does not

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
Roaders
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Jan 15, 2024 1:33 pm
Contact:

Logic network: do one thing when condition matches and do another thing when it does not

Post by Roaders »

Hi All

I've been trying to implement my first moderately complicted logic expression to control my train at a station. As I mention in another post I need probably 10 combinators or so. I want to try and minimise the number of combinators I use and also avoid duplicating logic.

I have a number of goods that I want to control unloading of. Each good has a different target quantity. For example I want to have 50 power poles off loaded. I set a constant combinator to 50. I then use a decide to calculate if the number of poles in the logistic network is greater than or equal to that. If it is greater than or equal I want my train to leave - that bit is all fine!

How do I use the same combinator to control the inserter that is offloading the train. If I have enough poles then I output 1 from the combinator indicating that the train should leave - how can I turn on the insterter if the value is not set?

It seems that this might not be possible and that I might need to duplicate the logic and the number of poles that I require inside the inserted enablement condition.

Thanks for the help.

Trific
Fast Inserter
Fast Inserter
Posts: 147
Joined: Thu Dec 31, 2020 7:57 pm
Contact:

Re: Logic network: do one thing when condition matches and do another thing when it does not

Post by Trific »

Enable the inserter if the value is 0.

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

Re: Logic network: do one thing when condition matches and do another thing when it does not

Post by Tertius »

You have a target quantity (usually stored in a constant combinator), you have items already present (usually read from a chest or from the logistic network), and you have items available in the source (usually read from a train station).

From all this, compute the amount of items to unload. Take the items you get from a chest and multiply this with -1 with an arithmetic combinator. Wire it to the target quantity, so the implicit add operation performed by wiring stuff together results in "amount of items to unload minus items already present". This is the amount of items we need to unload.
You can use this value for an inserter activation condition: amount of items to unload > 0.

You can also set the stack size to the amount of items to unload, so you're exactly unloading the amount you want, and not always full hands.

To be handle the stack size is easier than one might think.
Suppose you have multiple items to unload, and all items are on one wire.
Connect a decider combinator and use "ANYTHING" >0 (the green wildcard) as condition, and ANYTHING as output. This will pick one random item from the input. Connect this to a stack filter inserter. Set it to "set filter" instead of "activate/deactivate". This one random item is what the filter inserter now will pick. Connect a second combinator and feed it with the output of the first. Set to EACH > 0 and output S=input counter. Connect its output to the filter inserter as well and enable setting the stack size with signal S. The second combinator will convert the random material amount into signal S to set the stack size.

Don't worry to set a stack size of 50, if you want to unload 50 items. The inserter will pick up not more than its actual hand size. But if the amount to transfer becomes smaller than the hand size, the actual hand size setting becomes relevant.

Roaders
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Jan 15, 2024 1:33 pm
Contact:

Re: Logic network: do one thing when condition matches and do another thing when it does not

Post by Roaders »

Yes @Tertius. That's making sense. If you just calculate the deficit then you can use that number in both places...
Thanks again.

Post Reply

Return to “Gameplay Help”