Order in which on_configuration_change events are processed?

Place to get help with not working mods / modding interface.
robot256
Smart Inserter
Smart Inserter
Posts: 1322
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Order in which on_configuration_change events are processed?

Post 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?
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
robot256
Smart Inserter
Smart Inserter
Posts: 1322
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Order in which on_configuration_change events are processed?

Post 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.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Post Reply

Return to “Modding help”