Snippet Custom Polled Wait

T.s.e

Wish I was old and a little sentimental
Reaction score
133
JASS:
library CustomWait
function CustomPolledWait takes real duration returns nothing
    local timer t
    local real  timeRemaining

    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop
            set timeRemaining = TimerGetRemaining(t)
            exitwhen timeRemaining <= 0
            
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
        call DestroyTimer(t)
        set t = null
    endif
endfunction
endlibrary

This is basically the same as the regular Polled Wait, except it does not leak a handle like the original does.
 
What's the advantage of this over just simply using TriggerSleepAction?
I'm pretty sure TriggerSleepAction is the one that doesn't screw up when someone is lagging on the map also right?
 
PolledWait is slightly more accurate I believe, and this is just a fixed version of PolledWait (since the original has a handle leak)

Nice to see that someone actually submitted this :D

I'm pretty sure TriggerSleepAction is the one that doesn't screw up when someone is lagging on the map also right?

Nope, TriggerSleepAction goes through pauses in games such as lag window (while PolledWait stops until the window has disappeared), unless stopping itself when the lag window appears, then restarting it afterwards is a bad thing
 
TriggerSleepAction, I believe, has a delay sometimes determined on the amount of players playing. Vexorian's polled wait is better because it creates a global timer rather than creating and destroying one everytime on execution.

You can find it at Wc3jass.com. It is a non-leaking polled wait. Not sure if I've ever gotten it to work though. :p

This is fine I guess, but you basically just added the "set t = null". :p
 
Yes, it's not a bad thing to stop, and restart it afterwards because when someone is lagging it's usually a problem syncing and running more triggers instead of waiting it could cause more lag or disconnect the lagging player.

You should definitely update this by adding a private global timer and just using it in the function also wouldn't need to set it to null/destroy it i think after use cause it's a global.
 
I'd rather have MUI-ness than 2 less lines of code anytime.
 
A PolledWait is more accurate because it doesn't run through game pauses/lag. As you can see in the code, it loops (which are put on hold during a pause) to keep a small wait going, so the most time that it can possibly run through during lag is .1 seconds (unless there is left than 2 seconds left).
 
I'd rather have MUI-ness than 2 less lines of code anytime.

Um.. Yeah, that is fine. I mean sure, practically everyone would have 2 more lines just for MUI-ness. :)

But I don't see how that relates to the function. It is still MUI. :p

http://wc3jass.com/viewtopic.php?t=206

I think... :\ I'm not positive, I think there might be a few bugs with it though.

If you periodically use that PolledWait it might affect the gameplay a bit. If you use it for some spell or something or you don't use it like every 0.03 seconds, I think it should be fine. xP
 
Will the code work after the timer stops though at all?
It doesn't seem to make sense that it would.
JASS:
    if st <= 0 then
        set bj_gameStartedTimer = CreateTimer()
        call TimerStart(bj_gameStartedTimer, 1000000, false, null)
//So basically this system just ends if the timer reaches 1000000 because it doesn't reset it back to 0.
//also running it for 1000000 is bad as the comments say probably as theres maybe a max limit to how long a timer 
//could run without flipping out
    endif
Come to think of it... Vex's hero arena did seem to suddenly end after a certain amount of game time was played.


So far this is my solution:
JASS:
library CustomWait initializer InitWait
function RestartWait takes nothing returns nothing
//Restarts the timer once it ends again and again.
call TimerStart(bj_gameStartedTimer, 7200, false, function RestartWait)
endfunction

function InitWait takes nothing returns nothing
 local real st=TimerGetElapsed( bj_gameStartedTimer)
    if st <= 0 then
//starts the game timer
        set bj_gameStartedTimer = CreateTimer()
        call TimerStart(bj_gameStartedTimer, 7200, false, function RestartWait)
    endif
endfunction

function CustomPolledWait takes real duration returns nothing
 local real timeRemaining
 local real st=TimerGetElapsed( bj_gameStartedTimer)
    if (duration > 0) then
        loop
            set timeRemaining = duration - TimerGetElapsed( bj_gameStartedTimer) + st
//Right here it makes use of just using one single timer that starts as soon as the game starts by subtracting it to 
//get a duration passed making it MUI.
            exitwhen timeRemaining <= 0
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
    endif
endfunction
endlibrary
 
Sure it makes sense that it would work again.
JASS:
function CustomPolledWait takes real duration returns nothing
    local timer t
    local real  timeRemaining

    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop

It checks if duration is larger than 0, then if it is, it creates the timer and starts it.
EDIT: You were talking about Vex's wait thingy, aha.
 
General chit-chat
Help Users
  • The Helper The Helper:
    Happy Tuesday Night!
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top