Page 1 of 1

Get rail adjacent to train stop

Posted: Sat Jan 27, 2018 5:23 pm
by charlesrymal
Is there a way, if you have a train stop entity, to get the rail to which the train stop is attached? And vice versa?

And if you can get the rail, how could I figure out with direction to use with get_connected_rail to be forward relative to the train stop?

Re: Get rail adjacent to train stop

Posted: Sun Jan 28, 2018 12:15 am
by bobingabout
To find the rail next to a station, you'll probably have to resort to using a find in the area around the station, on the surface the station is on, then check to see if it is a rail.
http://lua-api.factorio.com/latest/LuaS ... ind_entity

That's how you detect what rails are connected to the rail that you find.
http://lua-api.factorio.com/latest/LuaE ... ected_rail

for which direction is forward, you can probably go off the direction that station is facing
http://lua-api.factorio.com/latest/LuaE ... .direction

Re: Get rail adjacent to train stop

Posted: Sun Jan 28, 2018 4:30 am
by eradicator
bobingabout wrote:for which direction is forward, you can probably go off the direction that station is facing
http://lua-api.factorio.com/latest/LuaE ... .direction
I was going to suggest using the stations direction. But i was kinda hoping someone would know a proper way to do this in the API. Going from the direciton of the station there can also be only exactly one possible position with a rail that is connected to the station, so not really any need to search the whole area once you determine the magic position offset.

Re: Get rail adjacent to train stop

Posted: Sun Jan 28, 2018 6:48 pm
by bobingabout
unfortunately, to get an entity at a location, you still need to search that location. I also linked to a point where you can see different search options, so you don't have to use the area one.

Re: Get rail adjacent to train stop

Posted: Mon Jan 29, 2018 12:30 am
by eradicator
bobingabout wrote:unfortunately, to get an entity at a location, you still need to search that location. I also linked to a point where you can see different search options, so you don't have to use the area one.
Sure. But you also said "in the area around the station". So i just added that theoretically/logically there can/should be only one possible position. I.e. if the station is facing upwards, then the only connectable rail is on the left side of the station, probably at {station.position.x - 2, station.position.y}.