Can I check pending events? Can I make on_tick function run last and not first?
Posted: Wed Aug 04, 2021 5:21 pm
I have two functions :
script.on_event({defines.events.on_train_changed_state},__train_changed_state)
script.on_event({defines.events.on_tick},__on_tick)
I must know if train changed state before on tick, because if it changed state, I stop train, but function __on_tick is always firing before __train_changed_state.
I already tried registering them in reverse order but it didn't helped.
Without looking for __train_changed_state game crashes, because I "try to change direction of automatic train", but I can't look it up before on_tick. (I know it is always firing after __on_tick, because I tried some game.prints() and those in __train_changed_state never fire up right before crash.
My on-tick code overwrites train physics, so it will indeed try to change direction of automatic train if it was moving in opposite direction. (it just sets speed, it doesn't look what speed is set by game)
I need to know in __on_tick if there's pending __train_changed state event, or I must get some post-tick function and I can move my __on_tick code here..
I also tried some weird methods like looking if train state was manual in last tick and isn't now, but it also won't cut it, because if it was automatic moving forward and I change it to automatic-backward it won't "flip" state and will crash..
Now that I think about it, I could check each frame for what station is next and if it changes, instantly stop train, but.... I want more elegant solution
script.on_event({defines.events.on_train_changed_state},__train_changed_state)
script.on_event({defines.events.on_tick},__on_tick)
I must know if train changed state before on tick, because if it changed state, I stop train, but function __on_tick is always firing before __train_changed_state.
I already tried registering them in reverse order but it didn't helped.
Without looking for __train_changed_state game crashes, because I "try to change direction of automatic train", but I can't look it up before on_tick. (I know it is always firing after __on_tick, because I tried some game.prints() and those in __train_changed_state never fire up right before crash.
My on-tick code overwrites train physics, so it will indeed try to change direction of automatic train if it was moving in opposite direction. (it just sets speed, it doesn't look what speed is set by game)
I need to know in __on_tick if there's pending __train_changed state event, or I must get some post-tick function and I can move my __on_tick code here..
I also tried some weird methods like looking if train state was manual in last tick and isn't now, but it also won't cut it, because if it was automatic moving forward and I change it to automatic-backward it won't "flip" state and will crash..
Now that I think about it, I could check each frame for what station is next and if it changes, instantly stop train, but.... I want more elegant solution