Page 1 of 1

Order in which on_configuration_change events are processed?

Posted: Fri Apr 12, 2019 10:59 pm
by robot256
I have a scenario where Mod A has a global Table, and Mod B wants to read items from Mod A's table with a remote interface and add new ones based on what it finds.

Mod A's on_configuration_change handler:
1 Check if Table exists.
2 If not, create Table and add default entries.

Mod B's on_configuration_change handler:
1 Read Table[item1] using Mod A's interface
2 Insert Table[item2] using Mod A's interface

I'm getting an error because when Mod A's on_configuration_changed event runs after Mod B's, Table[item1] might not exist. If it can't be read, then Table[item2] will never be written, and that will cause problems down the road even if I prevent Mod B from crashing by checking for nil.

It seems like adding Mod A as a dependency for Mod B fixes the problem. Is this the correct solution, or is it a coincidence and I should look for a better way?

Re: Order in which on_configuration_change events are processed?

Posted: Sat Apr 13, 2019 12:55 am
by robot256
Think I answered my own question. Very first line of the Data Lifecycle page says
Factorio sorts mods first by dependencies then by natural sort order accounting for case
That implies the same sort order is applied at every point where arbitration between mods is required, including on_configuration_change and other event handlers that might have more than one mod subscribed to them.