[2.0.76] LuaEntity.connected_rail_direction

Place to post guides, observations, things related to modding that are not mods themselves.
User avatar
hgschmie
Fast Inserter
Fast Inserter
Posts: 186
Joined: Tue Feb 06, 2024 5:18 am
Contact:

[2.0.76] LuaEntity.connected_rail_direction

Post by hgschmie »

I am trying to understand the function of LuaEntity#connected_rail_direction. I have these four train stops:
Screenshot 2026-05-12 at 11.00.52.png
Screenshot 2026-05-12 at 11.00.52.png (3.94 MiB) Viewed 124 times
All four report a connected_rail_direction of "0" (which is defines.rail_direction.back). Under which circumstances would a train stop report defines.rail_direction_front. And what exactly does that direction represent?
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4541
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [2.0.76] LuaEntity.connected_rail_direction

Post by boskid »

When a train goes to a train stop, the pathfinder is pointed at a specific rail as a path goal, but that information alone is not enough as it would allow train to approach that rail from either side. Because of this the trains pathfinder must be also told what is the rail direction of the target rail related to the direction it should approach it. As it is implemented right now, all horizontal and vertical straight rails obey the same set of rules about where the front and back is, which means value returned by LuaEntity::connected_rail_direction currently only depends on the direction of the train stop itself and does not require it to be attached to any rail. You can also use `show-rail-connection-points` debug layer to see where fronts and backs of each rail are and how does it correspond to the value returned by LuaEntity::connected_rail_direction.
Post Reply

Return to “Modding discussion”