I want to use LuaEntity.get_connected_rail together with LuaTrain.front_rail and LuaTrain.rail_direction_from_front_rail. So in my mod I implemented the following algorithm (pseudocode):
Code: Select all
local front_rail = some_train.front_rail
local dir = some_train.rail_direction_from_front_rail
local n = 0
local path = {}
while n < 10 do
table.insert(path, front_rail)
front_rail = front_rail.get_connected_rail{rail_direction=dir, rail_connection_direction=defines.rail_connection_direction.straight}
n = n+1
end
For the first time it actually returns NEXT rail, but for the next time in the same direction it returns PREVIOUS rail o_O At the moment this method is kinda unusable due to this problem.
I could share some code or screenshots if needed.