Page 1 of 1

[0.18.19] get_rail_segment_entity returns nil for rail signals at nearer position on rail

Posted: Thu Apr 23, 2020 11:15 pm
by Phoenix27833
Rail signals have two placement positions on a straight rail.

If the rail signal is at the further away position from the source rail for get_rail_segment_entity, the rail signal entity is returned.
However if the rail signal is at the closer position, get_rail_segment_entity returns nil.

I expect it to return the signal in both cases.

Re: [0.18.19] get_rail_segment_entity returns nil for rail signals at nearer position on rail

Posted: Fri Apr 24, 2020 5:17 am
by boskid
84128-setup.png
84128-setup.png (50.05 KiB) Viewed 1173 times

Code: Select all

/c
    local rail = game.player.selected
    game.print("front in: "..rail.get_rail_segment_entity(defines.rail_direction.front, true).unit_number)
    game.print("front out: "..rail.get_rail_segment_entity(defines.rail_direction.front, false).unit_number)
    game.print("back in: "..rail.get_rail_segment_entity(defines.rail_direction.back, true).unit_number)
    game.print("back out: "..rail.get_rail_segment_entity(defines.rail_direction.back, false).unit_number)
This works fine for me, it shows unit number of every of the 4 rail signals.

I suspect you may be confused about where the rail segment end is.
84128-two-segments.png
84128-two-segments.png (48.63 KiB) Viewed 1173 times
In above case, there are 2 rail segments, left one will have 2 signals and right (with single rail piece) will have another 2 signals

Re: [0.18.19] get_rail_segment_entity returns nil for rail signals at nearer position on rail

Posted: Fri Apr 24, 2020 3:40 pm
by Phoenix27833
Segment - a series of rails that are not split in between by junctions, signals or stations. The basic unit for pathfinder.
Image

Above returns nil in all cases

Image

Above works fine

Re: [0.18.19] get_rail_segment_entity returns nil for rail signals at nearer position on rail

Posted: Fri Apr 24, 2020 3:54 pm
by boskid
Due to the signals, you have 3 rail segments on both images. In first case left segment will have 2 signals, center segment will have 0 signals and right segment will have 2 signals. In second case left segment will have 0 signals, center segment will have 4 signals and right segment will have 0 signals. This is working as expected and is not going to change.