Quantcast Countdown / wait till function is done - ESOUI
Thread Tools Display Modes
04/17/19, 05:11 PM   #1
Join Date: Mar 2019
Posts: 24
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
  4.   while GetGameTimeSeconds() < futureTime do end
  5. end
  7. local function testSounds()
  8.   local duration = 5
  9.   local count = 1;
  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)

Last edited by Supportic : 04/17/19 at 05:13 PM.
  Reply With Quote
04/17/19, 05:21 PM   #2
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 2,626
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
  Reply With Quote
04/17/19, 05:23 PM   #3
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 99
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' ()
  Reply With Quote
04/17/19, 05:33 PM   #4
Join Date: Mar 2019
Posts: 24
Okay, thank you both, I will target the issue tomorrow. self:sleep(8h)
  Reply With Quote
04/18/19, 08:16 AM   #5
Join Date: Mar 2019
Posts: 24
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 = {
  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;
  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
  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
  19. SLASH_COMMANDS["/test"] = testSounds

Last edited by Supportic : 04/18/19 at 08:25 AM.
  Reply With Quote
04/18/19, 08:19 AM   #6
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 2,626
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.
  Reply With Quote
04/18/19, 08:33 AM   #7
Join Date: Mar 2019
Posts: 24
This would be just too easy. 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.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Countdown / wait till function is done

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off