[0.14.21] on_train_changed_state does not always fire

Bugs that are actually features.
Post Reply
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2916
Joined: Sat Jun 11, 2016 6:41 am
Contact:

[0.14.21] on_train_changed_state does not always fire

Post by Optera »

When adding/removing carriages to an automatic train parked at a train stop it switches to manual without raising on_train_changed_state.
Expected behavior would be to raise on_train_changed_state(event.train.state = defines.train_state.manual_control)

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.14.21] on_train_changed_state does not always fire

Post by Rseding91 »

In that instance the state is not changing. The old train is deleted and a new train in a different state is created. Thus no event is fired.

That's expected behavior.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2916
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [0.14.21] on_train_changed_state does not always fire

Post by Optera »

Is there an on_create event fired or do you have to check for this in on_tick?

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [0.14.21] on_train_changed_state does not always fire

Post by Nexela »

Optera wrote:Is there an on_create event fired or do you have to check for this in on_tick?
You should be able to find some ideas on how to handle this by looking at smart-trains mod or stdlib/trains stuff.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2916
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [0.14.21] on_train_changed_state does not always fire

Post by Optera »

Nexela wrote:
Optera wrote:Is there an on_create event fired or do you have to check for this in on_tick?
You should be able to find some ideas on how to handle this by looking at smart-trains mod or stdlib/trains stuff.
Quite some hacks needed to get a train stop notice changed train states reliably through on_built_entity, on_preplayer_mined_item, on_entity_died.
It still feels like on_train_changed_state should fire when creating a new train with the same unit numbers, backer names and object references.

Post Reply

Return to “Not a bug”