[vJass] Countdown Timer in One Trigger

Carl-Fredrik

New Member
Reaction score
51
Hey everybody (again).

I've heard that one of the advantages with Jass and vJass is that you may create a timer in one trigger instead of using severeal (In GUI you need one trigger to initialize it and start it and one to detect when it expires)... so I wanted to try this. I came this far (not sure if this is good, tell me if it can be improved):

JASS:
scope Timer initializer Init
private function Actions takes nothing returns nothing
    local timer GameTimer
    local timerdialog GameTimerDialog
    call StartTimerBJ( GameTimer, false, 600.00 )
    call CreateTimerDialog (GameTimer)
    call TimerDialogSetTitle (GameTimerDialog, "Time Left")
    set GameTimerDialog = GetLastCreatedTimerDialogBJ()
    call TimerDialogDisplay( GameTimerDialog, true )
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterTimerEventSingle( trig, 1.00 )
    call TriggerAddAction( trig, function Actions )
endfunction
endscope


Problem 1: Nothing happens o_O
Problem 2: I guess I need more than one function with actions to make the trigger detect when the timer expires.. but how do I fix so that it won't happen after 1 second, but when the timer expires?? :confused:

Thanks in advance!
// Carl-Fredrik
 
Reaction score
456
JASS:
scope GameTimer initializer Init

    private function Actions takes nothing returns nothing
        call BJDebugMsg("Expired!")
    endfunction

    private function Init takes nothing returns nothing
        local timer t = CreateTimer()
        call TimerStart(t, 1.00, true, function Actions)
        set t = null
    endfunction

endscope

In the map initialization you create and start the timer. Simple.

To get the timer in the handler function, you have to call GetExpiredTimer().
 

Carl-Fredrik

New Member
Reaction score
51
JASS:
scope GameTimer initializer Init

    private function Actions takes nothing returns nothing
        call BJDebugMsg("Expired!")
    endfunction

    private function Init takes nothing returns nothing
        local timer t = CreateTimer()
        call TimerStart(t, 1.00, true, function Actions)
        set t = null
    endfunction

endscope

In the map initialization you create and start the timer. Simple.

To get the timer in the handler function, you have to call GetExpiredTimer().

I'm new at vJass (and Jass), I dunno how to use handles... u want me to put that code in the Map Script, then what?
 

saw792

Is known to say things. That is all.
Reaction score
280
A 'handler' is not a handle. A 'handler' is a function that is run from another function through ForGroup, TimerStart or anything else that uses a code attribute (that is how I understand it anyway... it's a fairly generic term).

You can put that code anywhere you like. It is inside a scope.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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