Page 1 of 1

### Fuelling a locomotive with conditions

Posted: Sun Jan 10, 2021 11:19 am
Let's say I have a box with 50 pieces of solid fuel. And the task is, when a locomotive stops at the station, I want to load only 2 pieces of that fuel in it. How to do it??

I tried to fiddle with the station signals, decider and arithmetic combinators with several boxes and inserters, however, no matter what I tried it either did not load the locomotive at all, or it kept loading and loading (ignoring any conditions about the 2 pieces limit). Can somebody please help me with a screenshot of the setup and a detailed description of wiring and combinators (if used)?

### Re: Fuelling a locomotive with conditions

Posted: Sun Jan 10, 2021 1:58 pm
I would use a counter, to count how many pieces of fuel have been loaded.
I would use that counter to control the inserter, so it would only load when the count is less than 2. Limit the stack size on the inserter to 1.
I would use a latch that resets when the train enters the station so the next train also gets loaded. The reset would set the count back to zero.
Hmm and might need a second latch to distinguish a train entering the station from a train being at the station, so the first latch doesn't reset right away and just keeping loading the first train...

### Re: Fuelling a locomotive with conditions

Posted: Sun Jan 10, 2021 2:10 pm
In theory I have some many ideas and I know exactly how to do it. Just when I start wiring and using combinators, it doesn't work. Thats why I need help, like a screenshot and description of combinators' settings. I just can't figure it out, how to connect everything properly.
Amarula wrote:
Sun Jan 10, 2021 1:58 pm
I would use a counter, to count how many pieces of fuel have been loaded.
I would use that counter to control the inserter, so it would only load when the count is less than 2. Limit the stack size on the inserter to 1.
I would use a latch that resets when the train enters the station so the next train also gets loaded. The reset would set the count back to zero.
Hmm and might need a second latch to distinguish a train entering the station from a train being at the station, so the first latch doesn't reset right away and just keeping loading the first train...

### Re: Fuelling a locomotive with conditions

Posted: Sun Jan 10, 2021 2:24 pm
If anybody is interested in this task, posting a solution by Renan Gomes.

### Re: Fuelling a locomotive with conditions

Posted: Sun Jan 10, 2021 7:00 pm
I discovered it could be easier than I thought:

Overview:
Overview.png (282.58 KiB) Viewed 1245 times
One decider combinator, setting constant C to true (1) if a train is present to have fuel loaded.
Decider train present.png (37.41 KiB) Viewed 1245 times
One non-standard arithmetic combinator, counting the fuel as it is loaded into the locomotive.
Rather than adding zero to the count when another fuel is loaded by the inserter, it multiplies the fuel by the constant C. As soon as the train leaves the station, C becomes false, and the count is multiplied by zero.
Fuel counter when present.png (25.32 KiB) Viewed 1245 times
The inserter controls, to read the hand contents, and load fuel if the count is less than two:
Inserter read contents enable fuel less than 2.png (33.7 KiB) Viewed 1245 times
Hopefully this helps!

### Re: Fuelling a locomotive with conditions

Posted: Sun Jan 10, 2021 7:07 pm
Thank you for another interesting solution!
Amarula wrote:
Sun Jan 10, 2021 7:00 pm
I discovered it could be easier than I thought:
...

### Re: Fuelling a locomotive with conditions

Posted: Sun Jan 10, 2021 8:05 pm
I don't understand how this arithmetic combinator is wired to the system. The inserter keeps loading and loading, no matter what the train does
Amarula wrote:
Sun Jan 10, 2021 7:00 pm
One non-standard arithmetic combinator, counting the fuel as it is loaded into the locomotive.

### Re: Fuelling a locomotive with conditions

Posted: Mon Jan 11, 2021 11:32 am
Here is another solution using 1 combinator and a signal to reset the count after the train leaves the station. This makes sure everything only happens once per train. This works because when the train wants to leave, it reserves (yellow) the next signal it wants to pass.

2021-01-11 12_23_14-Window.png (364.94 KiB) Viewed 1038 times
2021-01-11 12_30_09-Window.png (63.6 KiB) Viewed 1038 times
2021-01-11 12_30_32-Window.png (119.08 KiB) Viewed 1038 times
2021-01-11 12_30_49-Window.png (57.31 KiB) Viewed 1038 times

### Re: Fuelling a locomotive with conditions

Posted: Mon Jan 11, 2021 12:37 pm
@disentius, this is so simple and elegant. i love it!

### Re: Fuelling a locomotive with conditions

Posted: Mon Jan 11, 2021 2:02 pm
darebakk wrote:
Sun Jan 10, 2021 8:05 pm
I don't understand how this arithmetic combinator is wired to the system. The inserter keeps loading and loading, no matter what the train does
Amarula wrote:
Sun Jan 10, 2021 7:00 pm
One non-standard arithmetic combinator, counting the fuel as it is loaded into the locomotive.
Wiring is standard for a counter: one wire from the inserter to the input of the counter combinator, and a second wire from the output of the combinator back into itself.
Plus one wire from the output of the decider combinator to deliver the control signal C to the input of the counter.

### Re: Fuelling a locomotive with conditions

Posted: Mon Jan 11, 2021 2:04 pm
disentius wrote:
Mon Jan 11, 2021 11:32 am
This works because when the train wants to leave, it reserves (yellow) the next signal it wants to pass.
Sweet!

### Re: Fuelling a locomotive with conditions

Posted: Mon Jan 11, 2021 2:06 pm
Amarula wrote:
Mon Jan 11, 2021 2:02 pm
darebakk wrote:
Sun Jan 10, 2021 8:05 pm
I don't understand how this arithmetic combinator is wired to the system. The inserter keeps loading and loading, no matter what the train does
Amarula wrote:
Sun Jan 10, 2021 7:00 pm
One non-standard arithmetic combinator, counting the fuel as it is loaded into the locomotive.
Wiring is standard for a counter: one wire from the inserter to the input of the counter combinator, and a second wire from the output of the combinator back into itself.
Plus one wire from the output of the decider combinator to deliver the control signal C to the input of the counter.
I think I misplaced a wire before, thats why it didnt work. However, I like the solution from disentius the best, because it uses only 1 inserter and 1 chest - perfect!

### Re: Fuelling a locomotive with conditions

Posted: Sat Jan 16, 2021 4:39 pm
Asking here rather than starting my own thread: how does one check he amount of fuel present in a locomotive?

This doesn't seem to happen in the above examples, or if it does, I'm totally missing it. To me it looks as if the inserter will count fuel into the locomotive whenever it stops at the station, regardless of how much it already has in the bunker. If the set amount doesn't exactly match consumption, the locomotive will, in due time, either fill up or run out.

I'm only getting started with circuit network stuff, but setting up an inserter to load items into a chest until an arbitrary amount has been reached is trivial and doesn't even require any combinators: just hook up the receiving chest with the inserter and you're good.

Trying to do the same with trains, it seems that the train contents as reported by the station pole only return the cargo, that is, the content of the carriages, but not the fuel in the locomotive itself. I can load 17 wood into a carriage, but not into the locomotive.

### Re: Fuelling a locomotive with conditions

Posted: Sat Jan 16, 2021 5:24 pm
Laie wrote:
Sat Jan 16, 2021 4:39 pm
Asking here rather than starting my own thread: how does one check he amount of fuel present in a locomotive?

This doesn't seem to happen in the above examples, or if it does, I'm totally missing it. To me it looks as if the inserter will count fuel into the locomotive whenever it stops at the station, regardless of how much it already has in the bunker. If the set amount doesn't exactly match consumption, the locomotive will, in due time, either fill up or run out.

I'm only getting started with circuit network stuff, but setting up an inserter to load items into a chest until an arbitrary amount has been reached is trivial and doesn't even require any combinators: just hook up the receiving chest with the inserter and you're good.

Trying to do the same with trains, it seems that the train contents as reported by the station pole only return the cargo, that is, the content of the carriages, but not the fuel in the locomotive itself. I can load 17 wood into a carriage, but not into the locomotive.
Your observation is good - there is no check how much fuel is left in the locomotive. The trick is different, I will explain it in a second. I was only asking how to do the loading of a specific number of items into something, in this case into a locomotive. I didnt care what was left in the locomotive, because when it comes to the station, the fuel will always be low. How I know? Im using a mod called "Automatic Train Fuel Stop" which calls the locomotive only when the fuel is low, automaticaly. So I know, by experience, how much fuel is left (approximately) when the locomotive comes and I set a reasonable number to fill it up.