HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

TimerUtils

10-02-2009, 11:09 PM#1
ShadowDestroyer
So, I have no idea how to use the timer functions. Is there a tutorial available for Vex's timer utils?

Basically, I am running a loop and I just want to have a .07 second wait in it. The polledwait is too inaccurate for this.
10-03-2009, 01:45 AM#2
Anopob
The comments in the library itself was sufficient to teach me, but anyway, instead of using a timer and doing CreateTimer() (or whatever it is) you use NewTimer(), like local timer t = NewTimer() and then when you're done you use call ReleaseTimer (t) If you need to transfer information to another function, use globals or structs.
10-03-2009, 01:47 AM#3
TriggerHappy
And call SetTimerData(timer, integer) is how to attach an integer to the timer.

call GetTimerData(timer) is to get the attached integer.
10-03-2009, 01:50 AM#4
ShadowDestroyer
Do timers immediately begin counting down when they are assigned an integer?

Can I not assign a small value, like .07 seconds?

So, how would I make a loop run every .07 seconds?
10-03-2009, 03:28 AM#5
Anopob
something like:
Collapse JASS:
scope Something

struct Something
    integer count
endstruct

function Callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local Something st = Something (GetTimerData (t)) // retrieving

    call BJDebugMsg (I2S (st.count))
    set st.count = st.count + 1

    if st.count > 10 then
        call ReleaseTimer() // no need for the timer anymore, destroy it
        call st.destroy()
    else
        call SetTimerData (t, st)
        call TimerStart (t, .07, false, function Callback) // repeat the loop actions
    endif
endfunction

function Something takes nothing returns nothing
    local timer t = NewTimer()
    local Something st = Something.create()

    set st.count = 5
    call SetTimerData (t, st) // attaching
    call TimerStart (t, .07, false, function Callback)
endfunction

endscope
Only an example of course. TimerUtils don't change the way you start timers. To answer your question: no.
10-03-2009, 03:31 AM#6
Rising_Dusk
Moved to triggers and scripts. At least post it in the right forum when you have so obviously a trigger question....
10-03-2009, 10:47 AM#7
Anitarf
If you just want a function to run periodically throughout the entire game, you don't even need TimerUtils, just create a timer at map initialization and then start it as a periodic timer.
10-03-2009, 11:20 PM#8
ShadowDestroyer
So, what would be equivalent to a "Wait .07 seconds" function?

Timers are confusing the heck out of me.
10-03-2009, 11:29 PM#9
Bobo_The_Kodo
Quote:
So, what would be equivalent to a "Wait .07 seconds" function?
Nothing.