LTN stop output gives wrong item count

Adds new train stops forming a highly configurable logistic network.

Moderator: Optera

Post Reply
mrvn
Smart Inserter
Smart Inserter
Posts: 5709
Joined: Mon Sep 05, 2016 9:10 am
Contact:

LTN stop output gives wrong item count

Post by mrvn »

I have a station that provides multiple items and does count perfect loading by removing any excess items.

This usually clears all loading inserters so when the next train arrives they pick up the right items and load them. But sometimes a full cargo wagon is requested. That means the inserters fill up the cargo wagon up to the last slot until no more can fit and then the train leaves. This can leave inserters with items in hand hovering over the track. Now the idea is that when the next train arrives the items are dumped into the cargo wagon. But then they are detected as excess items and removed again. So far the theory.

But what seem to happen is that the items are dumped into the arriving train before LTN output combinator gets programmed. I think this happens at the temporary stop

When LTN gets around to programming the output combinator the cargo wagon already contains the left over items and LTN sees that as "existing cargo". This then A) leaves the wrong items on the train, B) means the train has less slots for the actual cargo than LTN calculated and the loading may never finish.

Is this caused by the temporary stop with "0 second passed"? Will the inserters load the items at the temporary stop and then when LTN sees the train at the actual stop the cargo is already loaded? Wasn't there an LTN option to have temporary stops without condition so the train never actually stops there?

Or is the game just loading the items before the LTN event handler gets called? In that case couldn't LTN read the trains cargo content at the temporary stop so items help over the track aren't counted as existing cargo?

PS: I do see the option about not reporting existing cargo. But I would rather keep existing cargo and just have LTN report that correctly.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2916
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: LTN stop output gives wrong item count

Post by Optera »

mrvn wrote:
Tue Oct 04, 2022 6:20 pm
But what seem to happen is that the items are dumped into the arriving train before LTN output combinator gets programmed. I think this happens at the temporary stop
I know the issue, it's been there from day 1, long before temp stops even existed.
That's just how inserters operate. They shove their items into whatever inventory happens to park in front of them. Be it a wagon or locomotive regardless of train state.
mrvn wrote:
Tue Oct 04, 2022 6:20 pm
Or is the game just loading the items before the LTN event handler gets called? In that case couldn't LTN read the trains cargo content at the temporary stop so items help over the track aren't counted as existing cargo?
There's no time when reading train inventory is guaranteed to not include items shoved in by stuck inserters
Even reading inventories when trains start breaking for the stop, isn't save from pollution:
For example I build my long 12 car ore train stations with a signal after 4th and 8th car to increase throughput. If for whatever reason a train stops at those signals halfway in the station it'll collect all stuck items before triggering any train changed event for breaking at the stop.

I wish inserters would be as smart when loading trains as they are when loading assemblers, only grabbing as much as they can put into their target inventory. That's the only clean fix to this problem I can think of.

mrvn
Smart Inserter
Smart Inserter
Posts: 5709
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: LTN stop output gives wrong item count

Post by mrvn »

Optera wrote:
Tue Oct 04, 2022 7:37 pm
mrvn wrote:
Tue Oct 04, 2022 6:20 pm
But what seem to happen is that the items are dumped into the arriving train before LTN output combinator gets programmed. I think this happens at the temporary stop
I know the issue, it's been there from day 1, long before temp stops even existed.
That's just how inserters operate. They shove their items into whatever inventory happens to park in front of them. Be it a wagon or locomotive regardless of train state.
mrvn wrote:
Tue Oct 04, 2022 6:20 pm
Or is the game just loading the items before the LTN event handler gets called? In that case couldn't LTN read the trains cargo content at the temporary stop so items help over the track aren't counted as existing cargo?
There's no time when reading train inventory is guaranteed to not include items shoved in by stuck inserters
Even reading inventories when trains start breaking for the stop, isn't save from pollution:
For example I build my long 12 car ore train stations with a signal after 4th and 8th car to increase throughput. If for whatever reason a train stops at those signals halfway in the station it'll collect all stuck items before triggering any train changed event for breaking at the stop.

I wish inserters would be as smart when loading trains as they are when loading assemblers, only grabbing as much as they can put into their target inventory. That's the only clean fix to this problem I can think of.
Huh? No, that can't be (anymore). A train stopped at a signal has the cargo wagons locked down and inserters won't insert stuff:
train-at-signal.png
train-at-signal.png (557.17 KiB) Viewed 1084 times
Inserters also don't need to be smart enough to grab only what fits in an assembler. They stop inserting before the inventory is full so they never run into the case that stuff don't fit. The inventory of an assembler is also slightly larger than a stack (I think by 12, which is what a stack inserter can hold at max). I believe it's the assemblers that are "smart" in this case so inserters don't get stuck. But I might be wrong. You would have to test with something that has a low stack size and enough stack inserters to exceed the assemblers inventory.

Time to test this tick by tick in the map editor I guess to see what exactly the series of events is now. I'm sure this has changed sine day 1 of LTN.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2916
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: LTN stop output gives wrong item count

Post by Optera »

I didn't know inserters no longer load trains at signals, what a pleasant surprise.
Maybe the series of events has changed as well, you should also include a log writer for on_train_changed_state.

Post Reply

Return to “Logistic Train Network”