Page 1 of 1

How do dynamically (un)registered event handlers behave?

Posted: Tue Jan 30, 2018 5:34 am
by staviq
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 ?

Re: How do dynamically (un)registered event handlers behave?

Posted: Tue Jan 30, 2018 5:44 am
by Nexela
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

Re: How do dynamically (un)registered event handlers behave?

Posted: Tue Jan 30, 2018 7:22 am
by staviq
Ok, thanks.