Page 1 of 1

[Documentation] Page about event call order.

Posted: Sat Jul 14, 2018 3:25 pm
by eradicator
What?
The documentation doesn't seem to have a page about the order in which events are called in correlation to each other. Specifically things like:
"Is on_chunk_generated called after on_nth_tick"? (discussed here)
"Is on_tick called before on_nth_tick?" etc.
This: https://lua-api.factorio.com/latest/def ... nes.events list seems oddly un-alphabetical, so i'm not sure if that is the order. A dedicated page would be nice to have :).

Re: [Documentation] Page about event call order.

Posted: Sat Jul 14, 2018 11:42 pm
by Rseding91
on_tick is run before on_nth_tick and on_chunk_generated is run after on_tick.

The order of other events isn't defined. For example: robot built entity can happen any time during a tick any number of times along with robot-mined-entity any time during a tick any number of times.

Re: [Documentation] Page about event call order.

Posted: Sun Jul 15, 2018 6:25 am
by Optera
What about event handling results between mods?

Say mod 1 handles on_built_entity(mod1_entity) by deleting mod1_entity and replacing it with a different entity.
Will mods loaded after mod 1 also get on_built_entity(mod1_entity) with mod1_entity.valid = false?

Re: [Documentation] Page about event call order.

Posted: Sun Jul 15, 2018 10:49 am
by Rseding91
Optera wrote:What about event handling results between mods?

Say mod 1 handles on_built_entity(mod1_entity) by deleting mod1_entity and replacing it with a different entity.
Will mods loaded after mod 1 also get on_built_entity(mod1_entity) with mod1_entity.valid = false?
No, in that case the event calls simply stop because an invalid entity is invalid and can't even be compared to another entity in any meaningful way (like trying to check if a collection of nils is a specific nil).

Re: [Documentation] Page about event call order.

Posted: Mon Jul 16, 2018 5:06 pm
by eradicator
Rseding91 wrote:on_tick is run before on_nth_tick and on_chunk_generated is run after on_tick.

The order of other events isn't defined. For example: robot built entity can happen any time during a tick any number of times along with robot-mined-entity any time during a tick any number of times.
Arg, yes. Most events can occur multiple times ofc.

Are on_tick and on_nth_tick at least always guaranteed to be the first two events in each tick? (Could they be script.raise_event'ed to break that assumption?)