• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Time

Status
Not open for further replies.
Level 31
Joined
May 3, 2008
Messages
3,154
Ok, I am still not quite familiar with how timer should work. I seen the anitarf cinematic system where it use real to execute each call after an period of time have pass and then run other functions when it reach the max.

Example.

function 1
call bla bla (last for 2 seconds)
call bla bla (last for 3 seconds)
call bla bla (last for 8 seconds)
call execute function2
endfunction

function 2
call bla bla (last for 4 seconds)
call bla bla (last for 1 seconds)
call bla bla (last for 3 seconds)
endfunction

sorry if my explaination was bad, i am trying to create an precise timing cinematic via vjass.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Do the functions you are trying to execute have parameters?

Basically what a timer does is execute a function that takes nothing returns nothing after a designated amount of seconds (measured as a real). If you need to pass the delayed function parameters, then it gets a lot more complicated since you have to store those parameters as variables that can be referenced after. Depending on whether you want to have multiple instantiation capabilities then you will probably have to use a hash-table (or, if you're using TimerUtils, you have access to the SetTimerData function) to reference instance-specific data. If you don't really care, then global variables should suit your needs fine.

JASS:
scope Example initializer init
    public function initDelayed_2 takes nothing returns nothing

    endfunction
    public function initDelayed_5 takes nothing returns nothing

    endfunction

    public function init takes nothing returns nothing
        local timer after5sec = CreateTimer()
        local timer after2sec = CreateTimer()

        call TimerStart(after2sec, 2, false, function initDelayed_2)
        call TimerStart(after5sec, 5, false, function initDelayed_5)
        set after5sec = null
        set after2sec = null
    endfunction
endscope
 
Hopefully this is self explanatory.

JASS:
scope TimerTest initializer init

    // the callback function is the function which
    // is ran each time the timer is re-executed.
    private function Callback takes nothing returns nothing
        call BJDebugMsg("Timer Ran.")
    endfunction

    private function init takes nothing returns nothing
        // I've created descriptive locals to help you
        // better understand the TimerStart parameters.
        local real interval      = 0.03
        local boolean isPeriodic = true
        call TimerStart(CreateTimer(), interval, isPeriodic, function Callback)
    endfunction
    
endscope

Here's a tiny bit more advanced examples, using TimerUtils.
This is how you attach data to a timer, making it easier for MUI scripts.

JASS:
scope TimerUtilsTest initializer init

    private struct data
        integer someRandomVariable
    endstruct
 
    private function Callback takes nothing returns nothing
        local data d = GetTimerData(GetExpiredTimer()) // retrieve the correct struct instance
        call BJDebugMsg(I2S(d.someRandomVariable)) // confirm the integer is the correct one
    endfunction

    private function init takes nothing returns nothing
        local real interval      = 0.03
        local boolean isPeriodic = true
        local data d = data.create()
        local timer t = NewTimer()
        
        set d.someRandomVariable = GetRandomInt(1, 100)
        call BJDebugMsg(I2S(d.someRandomVariable)) // display the random int
        
        call SetTimerData(t, d) // store the struct instance
        call TimerStart(t, interval, isPeriodic, function Callback)
    endfunction
    
endscope
 
Status
Not open for further replies.
Top