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

Bugs that are actually features.
Post Reply
Phoenix27833
Inserter
Inserter
Posts: 47
Joined: Mon Aug 27, 2018 12:46 pm
Contact:

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

Post 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.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2227
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

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

Post by boskid »

84128-setup.png
84128-setup.png (50.05 KiB) Viewed 1139 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 1139 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

Phoenix27833
Inserter
Inserter
Posts: 47
Joined: Mon Aug 27, 2018 12:46 pm
Contact:

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

Post 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

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2227
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

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

Post 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.

Post Reply

Return to “Not a bug”