Generic train and combinators

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Nefish
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Mar 15, 2025 11:41 am
Contact:

Generic train and combinators

Post by Nefish »

Hi,

I have, on fulgora, a recycling station that take items we have too much of and either fully destroy them or extract useful component and send them to the train station that accept those items.

I'm working on the loading part of the scrap station and I'm trying to make a generic train. I'm trying to make it so that when a train arrive at the recycling loading station, the inserter select the items with the highest count and put them in the train. Then the train goes to a station depending on its content.

The train part is done.

My issue is trying to ensure the train is only loading one type of item.

An example of what I'm trying to do is: currently the station is receiving copper cable and green circuit. If there are more green circuits in the loading station's chest, when a train arrive at the station, I want this train to be loaded with only with green circuit, even if all the green circuits get loaded before the end of the train's waiting time. The selection of the item to load would only be remade when the next train arrive.
I also want the station to work for all items so that, for example, if I start adding plastic to the station I don't have anything to change.

I've tried using a selector combinator with the content of the chest of the loading station and either using the "select input" or "random input" modes (and setting the inserter's filter with the output of the combinator) but if the chests become empty during the loading, the output of the combinator will change depending on the next item inserted in the chest and the train end up getting loaded with a mix of items.
Also, in "select input" mode, if the item being loaded in the train stop being the item with the highest count in the chest, the output of the combinator will change.
"random input" isn't the behavior I'd want (if possible) and has the issue of the update of the output being in the middle of loading a train.

My first instinct was to use a memory that would be reset every time a train enter the station but the examples of memories I've found either work on number and not signal type or change output if a item (which wasn't the same as the previous output of the memory) is inserted a lot in the chest.

Is there a way to do what I want to do? If there is, how can I do that?
Shulmeister
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Mon Dec 23, 2024 11:00 pm
Contact:

Re: Generic train and combinators

Post by Shulmeister »

Do you have a blueprint of what you have attempted already ?

It sound like a RS latch would work, as you say a memory cell that choose what need be inserted in the train when a train arrive in the station, and get reset when a new train arrive.

It sound like it would require something additionnal to create a pulse when train arrive or depart, to make sure it could trigger the memory cell, there exist different ways to achieve this, one is to create a delay of 1 tick between a signal and its negative version. So when a train arrive it send a signal T, and just 1 tick after, you send -T by having this signal goes into an arithmetic combinator. Then when T isn't 0 it means either a train just arrived the previous tick.

Supposedly a RS latch would keep every type of signal that it received at the same time as a T signal, and forget them all when T is negative. I think you can achieve this with a decider combinator, that does "when T>0" output "everything". It's easier to describe the wiring and make sure the explanations are correct with a blueprint, that's why i asked if you had one already, to try and fiddle with it a bit.
Nefish
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Mar 15, 2025 11:41 am
Contact:

Re: Generic train and combinators

Post by Nefish »

Hi,

Since the bug in the design were blocking our production on fulgora, it was scrapped so I had to start again from half wired combinators. So I took the opportunity to make a full train track that showcase the issues I have.

Here's the blueprint:

Code: Select all

0eNrVXM2O47gRfpWFjoG84I9ISg3sAnvIMUAOAXIYNAzZVk8LI1teSe5Mo9EPkLfIs+VJQkr+UXcX7WJxsjuDOfRQtr76YVV9JYrmS7JqDtW+q3dDcveS1Ot21yd3n16Svv68Kxt3bVduq+Qu6cq6SV7TpN5tqq/JHX+9T5NqN9RDXU13jIPn5e6wXVWd/UJ6unN96J6qzcIBLMokTfZtb+9qdw7cIimVp8lzcrcwhlv8Td1V6+ljLl7TD7gCjauFB1cDsBKEXUHqyiOsLhDqZmhcbTy4kLoKDZsVJ1j1FhbSVqNhDb/AAkAGPUvZ2Wx2W78cDWvkBRYAKs5A/WAxPj8OI9Q1/ZSBgDhDI51V8iBxgk6g87kg6AQjSYJOEkTKCDrBSIqgEweRNEEnGMmE65QVIFIerpMHiRDjGRiZ4hLjDmi36Id2f63UWJjUCi2nDy1lDOWXKoGQOcFaWEdBsBaMeSEJOsFIGUEnMObFJea76vdD1Q9Vt1g/2r/gNPyszmg/u6p/vGf5UDf2xt59sZ/K7ETdJ05Pk/M33lw9iW7XX6ph8XConAm/H8rG6miv79puW7pL63a7L7tyaK3KyS/jhYNrLNTrvf0H2XXJwNWh+bKod33VWQUgq/L3Vs24IoOwDWEeYe/nhHkE64QoZs5ctfu2G651GJkImDzYw5LAT7DuksBPEqxMcp6rVdVgIlna6QexJCWCRrTbzZu8JHD1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yfIDsEflLPikUK3fH2wKnlfGVfBZoR+QYWAdfBarVgVKZRN8GusH5MzV+3/Zsav2nzKdqtQUqbpPP7k/qdvo7wbuLb5I3SsqMY70OFLTSMv5Z9PInEbTffo4Gu8zp/tyJyGXk4RpZNuEceTuT9066PhNM6IYcxyNKPa+aWTGUTGNcvv/1D1F8uNIpq4vvowcVZ9G9np+lJCPWlvp00i/uU+/ua9w9xVH6favGx01s3956hhDHkfZeN/0mcUeP8vsyF3NxpG4txNQD9V2fEFwOg04TZpyVVnaTf72z7/+dKGbn8Znw95+btm2H2fQzm2RFYXSnOUiz19f/wdIo8Z+
Tertius
Smart Inserter
Smart Inserter
Posts: 1190
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Generic train and combinators

Post by Tertius »

Is the task still the same: "Load the most available item into the train and nothing else"?

You can do it this way:
1. with a memory cell, create a snapshot of the station chest inventory the moment the train arrives
2. with a selector combinator, get the highest signal from the memory cell
3. use the output of the selector combinator to set the inserter filters for train loading

A 2.0 memory cell (the one that became possible with the 2.0 combinators) has 2 combinators. It stores and passes all input signals. It has a "SET" condition that decides if the memory cell either memorize and pass all input signals (SET) or pass the memorized signals (NOT SET).
The memory cell:
04-06-2025, 18-24-23.png
04-06-2025, 18-24-23.png (74.66 KiB) Viewed 421 times


Settings:
04-06-2025, 18-24-11.png
04-06-2025, 18-24-11.png (287.04 KiB) Viewed 421 times
Connect the collected chest content to the red wire input of that memory cell. Now look at the <S> signal. It's the "SET" signal. The top combinator is comparing S<>0 and the bottom combinator S=0. They're exactly the opposite. This way the top combinator passes the input if S<>0 (SET) and the bottom combinator passes the memorized value if S=0 (NOT SET)
However, we have a station that reports a train as T=0 if there is no train and T<>0 if there is a train. We want the remembered chest values if T<>0. That's the opposite of our S above, so we need to inverse the conditions in the combinators. So edit the S condition of the top combinator from S=0 to T<>0 and the S condition of the bottom combinator from S<>0 to T=0 and connect the green input of the bottom combinator to the station that's supposed to read the train id as T.

This means the memory cell will follow and output whatever the chest will contain as long as no train is at the station, and as soon as a train halts at the station, the memory cell will memorize the last chest values and output the memorized chest values from the moment the train arrived.

Now connect a selector combinator to the output of the memory cell and set it to return the largest signal and connect its output to the inserters and set the filters.

Your station will look like this:
04-06-2025, 18-51-47.png
04-06-2025, 18-51-47.png (444.58 KiB) Viewed 421 times
mmmPI
Smart Inserter
Smart Inserter
Posts: 4157
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Generic train and combinators

Post by mmmPI »

Shulmeister wrote: Thu Apr 03, 2025 6:45 pm It's easier to describe the wiring and make sure the explanations are correct with a blueprint, that's why i asked if you had one already, to try and fiddle with it a bit.
Attempted to follow the instructions, it works but uses 1 more combinator than the better solution Tertius proposed ?
Not sure because they are quite confusing and i had to improvise a little.



Nefish wrote: Sat Mar 15, 2025 12:17 pm Is there a way to do what I want to do ? If there is, how can I do that?
Seems like there are at least 2 !

using the command /editor and pausing time or making it go 1 update at a time is probably quite annoying in multiplayer but helps a lot when debugging those combinator builds, saying this because i saw the lamps in your blueprint and the "fast flicker failure" or whatever its proper name, when it happens and you don't want it it's annoying and not easy to understand what's going on.
Shulmeister
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Mon Dec 23, 2024 11:00 pm
Contact:

Re: Generic train and combinators

Post by Shulmeister »

Nefish wrote: Sun Apr 06, 2025 1:47 pm Hi,
Since the bug in the design were blocking our production on fulgora, it was scrapped so I had to start again from half wired combinators. So I took the opportunity to make a full train track that showcase the issues I have.
That's good it was possible to test the settings.
mmmPI wrote: Mon Apr 07, 2025 1:37 am Attempted to follow the instructions, it works but uses 1 more combinator than the better solution Tertius proposed ?
Not sure because they are quite confusing and i had to improvise a little.
Unfortunately, this will fail if the train ID is higher than the number of item to load onto it and there seem to be no easy way to fix without adding several combinators. It is what I had in mind though, so I would recommend using the other solution that comes with the detailed and not confusing explanations.
Tertius
Smart Inserter
Smart Inserter
Posts: 1190
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Generic train and combinators

Post by Tertius »

I just realized my proposed solution doesn't deal well with an edge case. If the most available item changes within 2 ticks after train arrival, the 1st inserter swing will carry the previous most available item, and the next swings will carry the proper item. This is because of the latency of 3 ticks of the signal path: station > memory cell > selector > inserters.

This can be corrected by connecting the memory cell with the selector combinator not with red wire but with green wire on the bottom decider. This decider will output nothing while there is no train, so the filters stay empty. Only if the memorized value is output, the inserters get the filter. And the intended filter only. The filters will be set 1 tick later than with the previous version, but I guess that's still an acceptable time frame :mrgreen:
mmmPI
Smart Inserter
Smart Inserter
Posts: 4157
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: Generic train and combinators

Post by mmmPI »

Shulmeister wrote: Mon Apr 07, 2025 4:08 pm Unfortunately, this will fail if the train ID is higher than the number of item to load onto it
true
Shulmeister wrote: Mon Apr 07, 2025 4:08 pm and there seem to be no easy way to fix without adding several combinators.

not true, although the train ID will stay in the memory cell, it is possible to add a single constant with large negative number to mask the ID.



Shulmeister wrote: Mon Apr 07, 2025 4:08 pm It is what I had in mind though, so I would recommend using the other solution that comes with the detailed and not confusing explanations.
Yeah i'm not so sure which one are the most confusing x)
Tertius wrote: Mon Apr 07, 2025 6:13 pm This can be corrected by connecting the memory cell with the selector combinator not with red wire but with green wire on the bottom decider. This decider will output nothing while there is no train, so the filters stay empty. Only if the memorized value is output, the inserters get the filter. And the intended filter only. The filters will be set 1 tick later than with the previous version, but I guess that's still an acceptable time frame :mrgreen:
like this ?

Nefish
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Mar 15, 2025 11:41 am
Contact:

Re: Generic train and combinators

Post by Nefish »

mmmPI wrote: Mon Apr 07, 2025 1:37 am using the command /editor and pausing time or making it go 1 update at a time is probably quite annoying in multiplayer but helps a lot when debugging those combinator builds, saying this because i saw the lamps in your blueprint and the "fast flicker failure" or whatever its proper name, when it happens and you don't want it it's annoying and not easy to understand what's going on.
I'm just starting to do stuff with combinators so I'm still at the "debug with prints" part of the learning process :). Thanks for the info!
Tertius wrote: Mon Apr 07, 2025 6:13 pm I just realized my proposed solution doesn't deal well with an edge case. If the most available item changes within 2 ticks after train arrival, the 1st inserter swing will carry the previous most available item, and the next swings will carry the proper item. This is because of the latency of 3 ticks of the signal path: station > memory cell > selector > inserters.
I used your solution and I noticed this issues. I haven't had a lot of time to play (that's also why I took so long to reply :( ) so I couldn't investigate it.


It works thanks to your answers. Now I can start over-engineering something else :D .

Thank you for answers!
Post Reply

Return to “Gameplay Help”