How to check if a station's connected rail segment is free?
Posted: Wed Jan 08, 2020 9:45 am
I'm trying to check if a rail segment connected to a train stop is unoccupied, so I can safely spawn a train there.
So far, I've got:
Unfortunately, it just keeps returning the train stop. How do I get it to return the entrance signal, so I can check its state?
So far, I've got:
Code: Select all
local station = -- some LuaEntity of type 'train-stop'
local rail = station.connected_rail
-- repeating this next step zero or more times doesn't seem to help
rail = rail.get_connected_rail {
rail_direction = defines.rail_direction.back,
rail_connection_direction = defines.rail_connection_direction.straight
}
local signal = rail.get_rail_segment_entity(defines.rail_direction.back, true)