View Single Post
07/19/22, 04:25 PM   #11
ZOS_DanBatson
ZOS Staff!
 
ZOS_DanBatson's Avatar
Yes this person is from ZeniMax!
Join Date: Jul 2015
Posts: 181
Originally Posted by Masteroshi430 View Post
It's an addon I am maintaining, there are some sort of loops of RegisterForUpdate exiting to an unregisterForUpdate by a condition.

So the new rule for RegisterForUpdate is :
- Always unregister before registering again otherwise the new register replaces the previous one with it's own milliseconds value restarting from scratch.
Am I right?
I will try to see what I can do.
Thanks Dan!
As of this change, there's literally no reason to unregister unless you're actually just trying to turn the update off. If you want to change what's currently registered (either do a different function, or change the interval, or reset the timer on the interval) you can register again as needed, no need to do the unregister first. You can do an unregister first if you want, but you don't need to and it provides no benefit.

Calling this every frame will result in myFunction() never getting called, because it will reset the clock every frame, and 50 ms never gets to elapse enough to fire the function.
Code:
EVENT_MANAGER:RegisterForUpdate("MyIdentifier", 50, myFunction())
Calling this every frame would be fine because the interval is 0, so it'll call it every frame anyway. But also calling this every frame is pretty pointless and indicative of potentially lazy code.
Code:
EVENT_MANAGER:RegisterForUpdate("MyIdentifier", 0, myFunction())
  Reply With Quote