How do dynamically (un)registered event handlers behave?

Place to get help with not working mods / modding interface.
Post Reply
staviq
Fast Inserter
Fast Inserter
Posts: 129
Joined: Wed Jun 29, 2016 1:22 pm
Contact:

How do dynamically (un)registered event handlers behave?

Post 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 ?

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

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

Post 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

staviq
Fast Inserter
Fast Inserter
Posts: 129
Joined: Wed Jun 29, 2016 1:22 pm
Contact:

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

Post by staviq »

Ok, thanks.

Post Reply

Return to “Modding help”