timer stack problem

Doomhammer

Bob Kotick - Gamers' corporate spoilsport No. 1
Reaction score
67
Before using stacks:

JASS:
function TimerPeriod takes nothing returns nothing
    local timer t2=GetExpiredTimer()
    local timer t=CreateTimer()
    call DestroyTimer(t2)
    set t2=null
    if (TimerGetRemaining(udg_Dialog_Timer)>1.0) then
        call StartSound( gg_snd_BattleNetTick )
        call TimerAura()
        call TimerStart(t, 2.0, false, function TimerPeriod)
    else
        call DestroyTimer(t)
    endif
    set t=null
endfunction

call TimerStart(udg_Dialog_Timer, 30.00, false, null)
call ExecuteFunc("TimerPeriod")


After implementing timer stacks:

JASS:
function TimerPeriod takes nothing returns nothing
    local timer t=NewTimer()
    call ReleaseTimer(GetExpiredTimer())
    if (TimerGetRemaining(udg_Dialog_Timer)>1.0) then
        call StartSound( gg_snd_BattleNetTick )
        call TimerAura()
        call TimerStart(t, 2.0, false, function TimerPeriod)
    else
        call ReleaseTimer(t)
    endif
endfunction

call TimerStart(udg_Dialog_Timer, 30.00, false, null)
call ExecuteFunc("TimerPeriod")


what it does: the global timer udg_Dialog_Timer counts 30 game seconds, the local timer in this function keeps calling its function, i.e. itself every 2 game seconds, until the global timer has less than 1 sec remaining.

My problem: way 1 works nicely repeating 15 cycles, way 2 counts 2 cycles and gives up. What's wrong here?
 

Doomhammer

Bob Kotick - Gamers' corporate spoilsport No. 1
Reaction score
67
I'm using recyclers from Vexorian's CSSafety

JASS:
    globals
        private timer array T
        private integer N = 0
    endglobals

    //==========================================================================================
    function NewTimer takes nothing returns timer
        if (N==0) then
            return CreateTimer()
        endif
     set N=N-1
     return T[N]
    endfunction

    //==========================================================================================
    function ReleaseTimer takes timer t returns nothing
        call PauseTimer(t)
        if (N==8191) then
            debug call BJDebugMsg("Warning: Timer stack is full, destroying timer!!")

            //stack is full, the map already has much more troubles than the chance of bug
            call DestroyTimer(t)
        else
            set T[N]=t
            set N=N+1
        endif    
    endfunction
 

substance

New Member
Reaction score
34
UMMMMM, well i've never used execfunc but you do this:
JASS:
call ReleaseTimer(GetExpiredTimer())
Well, if the function was called using ExecFunc then there was no 'expiredtimer'. I dunno how much that will effect anything, but that's all i see.
 

Doomhammer

Bob Kotick - Gamers' corporate spoilsport No. 1
Reaction score
67
on the first time function call, there won't be an expired timer, no matter if the function is called with ExecuteFunc, or with a simple call. That's not it.
 

substance

New Member
Reaction score
34
on the first time function call, there won't be an expired timer, no matter if the function is called with ExecuteFunc, or with a simple call.

That's my point? Think about it, what happens when you call ReleaseTimer()?
JASS:
            set T[N]=t
            set N=N+1
That might mess up the order of the timer stack.. or something...

I dunno but my point it you shouldnt try to release a timer that doesnt exist.
 

Doomhammer

Bob Kotick - Gamers' corporate spoilsport No. 1
Reaction score
67
Now I see...
...that you're absolutely right about it!

JASS:
unction TimerPeriod takes nothing returns nothing
    local timer t=NewTimer()
    local timer t2=GetExpiredTimer()

    if t2!=null then
	call ReleaseTimer(GetExpiredTimer())
    endif
    if (TimerGetRemaining(udg_Dialog_Timer)>1.0) then
        call StartSound( gg_snd_BattleNetTick )
        call TimerAura()
        call TimerStart(t, 2.0, false, function TimerPeriod)
    else
        call ReleaseTimer(t)
    endif
endfunction


thanks a lot for your help!

(+rep whenever can rep you again)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top