Page 1 of 1

get_train_stop_trains() behaviour when station name changed

Posted: Sat Nov 24, 2018 12:20 pm
by Sandman2003
If you have a single station with a train parked at it and you change the station name, then 'event.entity.get_train_stop_trains()' correctly returns the train that was in the single train stop. However, if there are more than one train stops with the same name, and a train is parked in one of these train stops and you change the train stop's name, then the same function, 'event.entity.get_train_stop_trains()' is unable to return that train. As this is based off the entity, not the backer name it should be able to function correctly.

This event is within a "script.on_event(defines.events.on_entity_renamed, function(event)" code block

In the single station case, the return looks like this -
{
{
__self = "userdata: 0x000000006d54bce0"
}
}

When there is more than one station with the same name (ie backer_name) then you get -
{}

(Results per game.write_file("trains",serpent.block(trains),{comment=false}))

- it is possible this is related to the same issue you fixed for 0.17 "Crash on LuaEntity.get_train_stop_trains() + train change" - however, I am not sure of this

Re: get_train_stop_trains() behaviour when station name changed

Posted: Sat Nov 24, 2018 3:11 pm
by Rseding91
Thanks for the report however this is working correctly. get_train_stop_trains() does not work based off entity but off the train stop name.

Additionally: train schedules won't be changed if there's still another train stop with the original name.

Re: get_train_stop_trains() behaviour when station name changed

Posted: Sat Nov 24, 2018 9:38 pm
by Sandman2003
I did actually ask about this one in discord first (mod_making). Anyway, my workaround works so it is all good. (And I knew about the train schedule, I assumed that was a consequence, but it seems it is more like the reason for this behaviour)