How to check if a station's connected rail segment is free?

Place to get help with not working mods / modding interface.
Post Reply
Jorn86
Long Handed Inserter
Long Handed Inserter
Posts: 70
Joined: Sun May 01, 2016 7:08 pm
Contact:

How to check if a station's connected rail segment is free?

Post by Jorn86 »

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:

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)
Unfortunately, it just keeps returning the train stop. How do I get it to return the entrance signal, so I can check its state?

Jorn86
Long Handed Inserter
Long Handed Inserter
Posts: 70
Joined: Sun May 01, 2016 7:08 pm
Contact:

Re: How to check if a station's connected rail segment is free?

Post by Jorn86 »

I tried putting the signals a lot closer, that actually causes them to be detected. However, that doesn't explain why they aren't detected further out (i.e. if the block is bigger).

Any suggestions would be welcome.

Post Reply

Return to “Modding help”