Order of rolling-stocks returned by LuaTrain properties?

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Order of rolling-stocks returned by LuaTrain properties?

Post by Deadlock989 »

I could maybe answer these questions myself but it would take a fair bit of work and quite a long time to set up tests, so maybe someone already knows from their own modding experience (or can peek at the source and find out).

LuaTrain has several useful ways of getting arrays of the entities that form a train. For example there is carriages which returns all rolling stocks, cargo_wagons which returns only the cargo wagons etc.

How is the order of these arrays determined? From limited testing it seems to be the order in which they were added to the train. So if you have a double-headed train, the order of the cargo wagons will be the same no matter which direction the train is moving. If a train is L1-C2-C3-C4-C5-L6 where L is a locomotive, C is a cargo wagon and the numbers indicate the order of placement and linkage, C2 will still be returned as the first cargo wagon when the train arrives "backwards" at a stop with L6 at the "front". That's all fine - as long as you can depend on it. Can you?

What happens if a train is broken in half and then re-joined?
Image

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2227
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Order of rolling-stocks returned by LuaTrain properties?

Post by boskid »

You may want to look at the 89114 - it has some details about carriages order. When you split train in half and rejoin it - it does not matter. Every split or join removes old LuaTrain (or 2 when merging) and creates new LuaTrain (or 2 when splitting/destroying by collision). When the LuaTrain is created the front rolling stock is choosed and from this point the order of carriages is immutable. If it would be to change that means new LuaTrain will be created.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: Order of rolling-stocks returned by LuaTrain properties?

Post by Deadlock989 »

Thanks, that helps a lot.
Image

Post Reply

Return to “Modding help”