I'd like to be able to read the current train limit of a station in a mod, but it doesn't seem to be exposed to Lua? I'm guessing I can get the number of trains that have reserved the station with a combination of `get_stopped_train()` and checking the `path_end_stop` for each train in `get_train_stop_trains()`, but that feels clunky and, in addition, I can't find anything that gets/sets the limit of the stop.
Ideally, I think LuaEntity would expose two properties, `train_stop_limit [uint, RW]` and `train_stop_reserved_by [array of LuaTrain, R]`
Happy to be pointed to the appropriate properties if they already exist.
[1.1.2] Expose train stop limit information to Lua
-
- Burner Inserter
- Posts: 9
- Joined: Fri May 22, 2020 6:56 pm
- Contact:
[1.1.2] Expose train stop limit information to Lua
Known as moogan in game.
Re: [1.1.2] Expose train stop limit information to Lua
Path of 1.1.0 changelog:
(they may have wrong returned type in doc saying LuaEntity while they return uint, this will be fixed in 1.1.3 doc)
General problem with the `train_stop_reserved_by` is that it is not a simply given value: i would have to visit all the trains and check if they have any reservation of a given train stop (due to waypoints logic train may have reservation for multiple train stops at once, even for the same one multiple times). Issue would be that the trains count could say 10 and if asked for train_stop_reserved_by it would only return (for example) 8 trains. It may still be better than doing that check lua side so it may still be good idea to have that.
Code: Select all
- Added LuaEntity::trains_limit read/write.
- Added LuaEntity::trains_count read.
- Added LuaTrainStopControlBehavior::trains_count_signal, trains_limit_signal, set_trains_limit and read_trains_count read/write.
General problem with the `train_stop_reserved_by` is that it is not a simply given value: i would have to visit all the trains and check if they have any reservation of a given train stop (due to waypoints logic train may have reservation for multiple train stops at once, even for the same one multiple times). Issue would be that the trains count could say 10 and if asked for train_stop_reserved_by it would only return (for example) 8 trains. It may still be better than doing that check lua side so it may still be good idea to have that.
-
- Burner Inserter
- Posts: 9
- Joined: Fri May 22, 2020 6:56 pm
- Contact:
Re: [1.1.2] Expose train stop limit information to Lua
I control-f'd for `limit` in the entity docs but I must have been bitten by a cache issue. Ah well, thanks for the sanity check!
Known as moogan in game.