I'm wondering,
If you define on_tick handler in a mod, but then do script.on_event({defines.events.on_tick},nil)
Does it trully unregister and use no ups, or it remains lost somewhere and causes performance trouble ?
I know it works, because i have tried it, but does this actually unregister the event handler ?
How do dynamically (un)registered event handlers behave?
Re: How do dynamically (un)registered event handlers behave?
It is truly unregistered and gone. And can lead to desyncs in multiplayer if not handled correctly.
You need to make sure to have a control variable in global and register in on_load if needed.
some_func = blah
on_load -> if global.some_var then on_tick = some_func
on_some_event -> global.some_var = false on_tick = nil
on_some_other_event -> global.some_var = blah on_tick = some_func
You need to make sure to have a control variable in global and register in on_load if needed.
some_func = blah
on_load -> if global.some_var then on_tick = some_func
on_some_event -> global.some_var = false on_tick = nil
on_some_other_event -> global.some_var = blah on_tick = some_func