I have two mods. Let's call them "Logistic Train Network" and "Train Tracker". Both listen to `on_train_changed_state`.
When a train stops at a station (transition from `arrive_station` to `wait_station`), the first mod (Logistic Train Network) receives an event with `old_state` = 5 (arrive_station) and train.state == 6 (wait_station). At this point, the mod resets the schedule of the train wihin the event handler.
Now the second mod does *not* receive the same event (which is what I would have expected), but a different event: `old_state = 5` (arrive_station) (that part is still ok) but the train state is now *also* `arrive_station`, not `wait_station`. The second mod *never* receives an on_train_changed_state event with train.state == 6 (wait_station) even though when polling the train (asking for its state), it will be `wait_station` at some later point. Only the event is never fired for any other mod as soon as one mod modifies the schedule.
I would have expected that event being fired for all mods that will be listening to it, independently what any of the mods does to the schedule.
This seems like a bug to me.
[2.0.66] event state 'wait_station' never fired when changing schedule in an event handler
Re: [2.0.66] event state 'wait_station' never fired when changing schedule in an event handler
If a mod invalidates the state of an event, and doing that
probably does invalidate it, the event does not propagate further. That is intended.the mod resets the schedule of the train wihin the event handler.
Re: [2.0.66] event state 'wait_station' never fired when changing schedule in an event handler
Thanks for the report however this is working correctly. The train event contains the old state, and the current state of the train. If a mod changes it during the event, all future events will be the current state of the train - not the state that it was at the time the event *started*.
Additionally, if a train transitions between multiple states within a single tick the event only fires for the final state. Additionally additionally - if a train transitions from state A to B to C then back to A all within the same tick - no event is fired.
These are limitations of how the event works for trains due to mods abilities to alter/break things during events.
Additionally, if a train transitions between multiple states within a single tick the event only fires for the final state. Additionally additionally - if a train transitions from state A to B to C then back to A all within the same tick - no event is fired.
These are limitations of how the event works for trains due to mods abilities to alter/break things during events.
If you want to get ahold of me I'm almost always on Discord.
Re: [2.0.66] event state 'wait_station' never fired when changing schedule in an event handler
<sad>, but not super-surprised. I assumed it would be something like this. Thank you for the thorough explanation, this helps me a lot to understand how the game sends events.
Let me see if I can figure out a workaround for my use-case.
(I don't think there is a way for a mod to register a priority, like in "call me first, I will not modify state" or so?
)
Again, thanks for the explanation.
Let me see if I can figure out a workaround for my use-case.
(I don't think there is a way for a mod to register a priority, like in "call me first, I will not modify state" or so?

Again, thanks for the explanation.