[vJass] Getting game time & periodic event

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
I have a few things that need to run every 5, 15, and 60 seconds. However I want to put them all in the same trigger and action so it prevents as much lag as possible because there are a lot of things that could be added. My main problem is not knowing a method for obtaining the game time. I've done some searching of the constants to no avail. Here's the code:

JASS:
scope PeriodicThings initializer InitTrig
private function PERIODIC takes nothing returns nothing
local integer time = GetIntegerGameState(???????)
    if ModuloInteger(time,60) == 0 then
        //do the actions that happen every 60 seconds
    endif
    if ModuloInteger(time,15) == 0 then
        //do the actions that happen every 15 seconds
    endif
    //do actoins that happen every 5 seconds
endfunction

private function InitTrig takes nothing returns nothing
local trigger trg = CreateTrigger()
    call TriggerRegisterTimerEvent(trg,5,true)
    call TriggerAddAction(trg, function PERIODIC)
endfunction
endscope
 

saw792

Is known to say things. That is all.
Reaction score
280
Just use a global TIME variable and increment it by 5 at the top of the periodic function.
 

DioD

New Member
Reaction score
57
this will cause much more lag due logic checks.

use 3 separate timers, not trigger to improve stability.
 

saw792

Is known to say things. That is all.
Reaction score
280
That depends entirely upon whether a function call is less intensive than registering a timer expiration/having the timer running.

It won't cause lag at all.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
A somewhat simple GameTime trigger could look something like this:

JASS:
library Gametime initializer Init
    globals
        public timer T = CreateTimer()
        public real R = 0.
    endglobals
    
    private function Callback takes nothing returns nothing
        set R = R + 3600.
    endfunction
    
    function GetGameTime takes nothing returns real
        return TimerGetElapsed(T) + R
    endfunction
    
    private function Init takes nothing returns nothing
        call TimerStart(T, 3600., true, function Callback)
    endfunction
endlibrary
 
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