ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Countdown / wait till function is done (https://www.esoui.com/forums/showthread.php?t=8472)

Supportic 04/17/19 05:11 PM

Countdown / wait till function is done
 
Hey, I just wonder if there is a way to pause a for-loop between every item.
My current approach is:

Lua Code:
  1. local function sleep(s)
  2.   local futureTime = GetGameTimeSeconds() + s
  3.  
  4.   while GetGameTimeSeconds() < futureTime do end
  5. end
  6.  
  7. local function testSounds()
  8.   local duration = 5
  9.   local count = 1;
  10.  
  11.   for key, value in pairs(UAN.Sounds) do
  12.     PlaySound(value)
  13.     Util.p("[%d]: %s", count, key)
  14.     count = count + 1
  15.     sleep(duration)
  16.   end
  17. end

But the for-loop is so fast, that it stacks all sleep-calls and causes to freeze the game. x)

Baertram 04/17/19 05:21 PM

What are you trying to approach?
MAybe you should have alook at LibAsync.

Or try to use
zo_callLater(function() ... end, delayInMS)
within the loop where delay will increase each time by 5 seconds and thus the code in the loop will just delay each PlaySound for 5, 10, 15, 20, ...seconds

Kyoma 04/17/19 05:23 PM

There's no proper "sleep" function in eso, try reading this page (https://wiki.esoui.com/Running_LUA-Code_asynchroneously) to see how to 'work around' the 'lack of sleep' (:p)

Supportic 04/17/19 05:33 PM

Okay, thank you both, I will target the issue tomorrow. self:sleep(8h) :rolleyes:

Supportic 04/18/19 08:16 AM

So basically I found this big Sound list on the wiki https://wiki.esoui.com/Sounds, so I decided to go through it and maybe find some sounds for my next addon. Entering everything by myself in chat with "/script PlaySound(SOUNDS.ABILITY_CASTER_DEAD)" wasn't the right solution for me so I decided to write a little script which iterates through the list and play each sound one by one after a certain amount of delay.

My list structure was this:

Lua Code:
  1. UAN.Sounds = {
  2.   ["ABILITY_CASTER_BUSY"] = SOUNDS.ABILITY_CASTER_BUSY,
  3.   ["ABILITY_CASTER_DEAD"] = SOUNDS.ABILITY_CASTER_DEAD,
  4.   ["ABILITY_CASTER_DISORIENTED"] = SOUNDS.ABILITY_CASTER_DISORIENTED,
  5.   ["ABILITY_CASTER_FEARED"] = SOUNDS.ABILITY_CASTER_FEARED,
  6.   ["ABILITY_CASTER_LEVITATED"] = SOUNDS.ABILITY_CASTER_LEVITATED,
  7.   ["ABILITY_CASTER_PACIFIED"] = SOUNDS.ABILITY_CASTER_PACIFIED,
  8. }

After my game freezed, everytime I wanted to make a pause between the sounds, some kindly devs suggested me to use LibAsync for my purpose.
LibAsync: https://www.esoui.com/downloads/info2125-LibAsync.html
How to LibAsync: https://wiki.esoui.com/Running_LUA-Code_asynchroneously

The solution for my problem which worked at the end was the following code:

Lua Code:
  1. local async = LibStub("LibAsync")
  2. local task = async:Create("wait")
  3. local count = 1;
  4.  
  5. local function someFunction(key, value)
  6.   PlaySound(value)
  7.   d(strfmt("[%d]: %s", count, key))
  8.   count = count + 1
  9.   -- delay my own task by doing nothing for 3s
  10.   task:Delay(3000, function() end)
  11. end
  12.  
  13. local function testSounds()
  14.   -- go through the list asynchronous and execute someFunction() in each step
  15.   task:For(pairs(UAN.Sounds)):Do(someFunction)
  16.   count = 0
  17. end
  18.  
  19. SLASH_COMMANDS["/test"] = testSounds

Baertram 04/18/19 08:19 AM

You could also use a LAM slider control to add the sounds to (build a choices tale by Looping over the SOUNDS table) and play them on setFunc change. Some of my addons like FCOStarveStop, FCOChatTabBrain or FCOUltimateSound use this.

Supportic 04/18/19 08:33 AM

This would be just too easy. :p Jokes aside, the funny thing is when I call the function in a current existing async task, it stops by default and starts again from the beginning.

My assumption was that I would create another task doing the same.


All times are GMT -6. The time now is 07:24 AM.

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