Don't need to apologize. Own your mistakes, because you learn and grow from them.
The reason I asked when create_stop_list() is called is that I tried debugging your code and manually called this function, and voila my missing stations appeared there and were handled. This probably means that the periodic call of the function did not work anymore. This is just my observation that might or might not give some insight.
What came to my mind looking at your code:
-
avoid code duplication, externalize recurring unchanged logic into small functions (e.g. the counting of active stops per schedule); this greatly increases readability and maintainability
-
avoid branching (if blocks) where it can easily be replaced with logic operations (e.g. setting a boolean: bool a = obj.prop ~= nil and obj.prop.isSomething )
if I create new stations, and I execute /remove_depots_from_trains before create_stop_list() is called the game crashes (index out of bounds)
I reckon this happens because the mod's stop list is missing the stops, where it adds depot stops, and when calling remove_depots_from_trains then tries to access them by indexer, which of course can't work. Here is the error message:
Error while running command "remove_depots_from_trains": Index out of bounds.
stack traceback:
[C]: in function 'newindex'
__train-depots/control.lua:111: in function 'replace_train_schedule'
train-depots/control.lua:764: in function <train-depots/control.lua:758>
How about we meet in Discord and debug this together?