[Documentation] Page about event call order.

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

[Documentation] Page about event call order.

Post 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 :).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

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

Re: [Documentation] Page about event call order.

Post 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.
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: [Documentation] Page about event call order.

Post 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?

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

Re: [Documentation] Page about event call order.

Post 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).
If you want to get ahold of me I'm almost always on Discord.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [Documentation] Page about event call order.

Post 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?)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding interface requests”