[Solved] Conditionally registering for custom event
Posted: Mon Apr 15, 2019 2:01 pm
I ran into an issue with a conditional event that I don't know how to solve. Here is the situation:
Any suggestions on how to solve this in a desync-free way?
- Mod A has an optional dependence on Mod B
- If Mod B exists, Mod A uses the remote interface to get a custom event ID from Mod A in on_init and on_configuration_changed:
Code: Select all
-- part of on_init and on_configuration_changed of Mod A if game.active_mods["Mod_B"] then global.custom_event = remote.call("Mod_B_interface", "get_event") script.on_event(global.custom_event, custom_event_handler) else global.custom_event = nil end - This is a conditional event and has to be re-registered in on_load:
Code: Select all
-- part of on_load of Mod A if global.custom_event then script.on_event(global.custom_event, custom_event_handler) end
Any suggestions on how to solve this in a desync-free way?