ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Terminate callLater (https://www.esoui.com/forums/showthread.php?t=9008)

ExoY 03/02/20 03:25 AM

Terminate callLater
 
Hello,

i was wondering if there is a way to terminate the zo_callLater function, before it executes?

Here a minimalistic example of what i mean.

Lua Code:
  1. function foo.EnterCombat()
  2.   zo_callLater(function() d("you take too long") end, 5000)
  3. end
  4.  
  5. function foo.LeaveCombat()
  6.   -- terminate the zo_callLater
  7. end

Besides the option to terminate the callLater i would also need a way to identify the specifiy callLater, maybe by some form of id or such.

Is it even possible to implement something like this with the currently availiable tools?


(I am aware that in certain situations a workaround can be achieved with "RegisterForUpdate" and "UnregisterForUpdate")

Thanks in advance

sirinsidiator 03/02/20 03:44 AM

You can! All you need to do is call UnregisterForUpdate for the name the callLater is registered with. It will return an id when you call it, so you can unregister it like this:

Lua Code:
  1. local function ClearCallLater(id)
  2.     EVENT_MANAGER:UnregisterForUpdate("CallLaterFunction"..id)
  3. end
  4.  
  5. function foo.EnterCombat()
  6.   foo.myHandle = zo_callLater(function() d("you take too long") end, 5000)
  7. end
  8.      
  9. function foo.LeaveCombat()
  10.   ClearCallLater(foo.myHandle)
  11. end

Baertram 03/02/20 04:33 AM

Background information:

zo_callLater is nothing else than an
EVENT_MANAGER:RegisterForUpdate
with a pre-defined identifier prefix "CallLaterFunction" and an attached suffix which is not pre-defined.

https://github.com/esoui/esoui/blob/...alapi.lua#L197

And either zo_callLater or EVENET_MANAGER:RegisterForUpdate both return the unique ID of the registered handler so you can use this one to unregister it again via EVENT_MANAGER:UnregisterForUpdate

ExoY 03/02/20 05:58 AM

Thank you both for the quick and precise answers.

It was exactly what i was locking for and now i also now what zo_callLater really does.


All times are GMT -6. The time now is 04:10 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI