View Single Post
06/24/18, 02:40 PM   #4
ArtOfShred
 
ArtOfShred's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 103
The other way is by using EVENT_MANAGER:RegisterForUpdate("name", function, timer)
You can then EVENT_MANAGER:UnregisterForUpdate("name") to stop the function from running if/when needed.

Note there's a lot of discussion over whether or not registering and unregistering events on a consistent basis is a good idea or not. I use it for a few things and I haven't noticed any negative impact from it.
Also it's widely excepted that you should avoid zo_callLater most of the time unless you're only using it sparingly or for something you absolutely need it for.

There is one nice advantage to RegisterForUpdate, and that is you can make a continuous throttle by reregistering the update function whenever a certain function triggers. I use this in LUI Extended to make a "x" variable duration throttle timer for Experience Gain for example. If the player goes 5 seconds without gaining XP then the saved value is dumped, reset, and the event is unregistered. If the player gains XP again during that 5 sec window, the event is reregistered and thus the timer restarts.
  Reply With Quote