list of train stations
Re: list of train stations
I don't think there is a specific function in the API capable of doing this, but you can iterate over all train stops:
The downside is that the code is very performance intensive, it takes a few ticks to run on my midsized map and the freeze is very noticeable. It also doesn't account for duplicate names, but you could add them as table keys first and then return a new list where the keys are converted to values.
Factorio probably has an internal list of current train stops, you could ask in the Modding interface requests subforum.
You could also maintain a list of all train stops by initially filling the list going over every train stop, then listening for on_built/on_mined/on_died events and changing the list accordingly. The only exception is the renaming of stops, but an event for this will be implemented in 0.15: Event: on_entity_renamed(entity)
Code: Select all
function get_trainstop_names(surface)
trainstops = {}
for _, trainstop in pairs(surface.find_entities_filtered{name="train-stop"}) do
table.insert(trainstops, trainstop.backer_name)
end
return trainstops
end
Factorio probably has an internal list of current train stops, you could ask in the Modding interface requests subforum.
You could also maintain a list of all train stops by initially filling the list going over every train stop, then listening for on_built/on_mined/on_died events and changing the list accordingly. The only exception is the renaming of stops, but an event for this will be implemented in 0.15: Event: on_entity_renamed(entity)
Re: list of train stations
can you move it to : Modding interface requests subforum ?