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?
Get rail adjacent to train stop
-
- Manual Inserter
- Posts: 1
- Joined: Sat Jan 27, 2018 5:13 pm
- Contact:
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Get rail adjacent to train stop
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
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
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Get rail adjacent to train stop
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.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
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Get rail adjacent to train stop
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.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Get rail adjacent to train stop
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}.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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.