Order of mod loading problem
Posted: Mon Aug 15, 2016 5:39 pm
I have a mod (let's call it "A") that does some initializing stuff in event "on_player_created". Another mod (let's call it "B") also does some initializing in event "on_player_created".
The problem is that mod A wants to call a remote method mod B expose when mod A receives the "on_player_created" event, but at this time mod B hasn't received the "on_player_created" yet, and is missing some initialization (i.e. setting some global["foo"]), causing the exposed method to fail as it relies on a completed initialization.
If I were to rename mod A to a name that starts with a letter later in the alphabet I'm betting it would work because then mod B would be done with event "on_player_created" by the time mod A handles the same event.
Currently I "solve" this with a hack in mod A:
But this really just is postponing the issue, if other mod makers starts doing the same you're just as far (you could of course make it wait until the 2nd, 3rd, etc. tick, but it's still a hack).
Is there a better way, am I missing something?
If not, should we design mods to emit a "mod_loaded" event that other mods can listen to and act accordingly?
The problem is that mod A wants to call a remote method mod B expose when mod A receives the "on_player_created" event, but at this time mod B hasn't received the "on_player_created" yet, and is missing some initialization (i.e. setting some global["foo"]), causing the exposed method to fail as it relies on a completed initialization.
If I were to rename mod A to a name that starts with a letter later in the alphabet I'm betting it would work because then mod B would be done with event "on_player_created" by the time mod A handles the same event.
Currently I "solve" this with a hack in mod A:
Code: Select all
script.on_event(defines.events.on_tick, function(event)
remote.call("ModB", "doSomething", params)
script.on_event(defines.events.on_tick, nil) -- remove this event listener
end)
Is there a better way, am I missing something?
If not, should we design mods to emit a "mod_loaded" event that other mods can listen to and act accordingly?