Create Timer with Structure

Tyrulan

Ultra Cool Member
Reaction score
37
Been experimenting with periodic timers and came up with this simple function.

JASS:
scope

    globals

        timer T
        real TCount = 0
        real TOTAL = 0

    endglobals

    function timerLoop takes nothing returns nothing       
        set TOTAL = TimerGetElapsed(T) + TCount 
        call BJDebugMsg("Timer: " + R2S(TOTAL))
        set TCount = TCount + 1
        
        if (TOTAL == 15.00) then
            call DestroyTimer(T)
            call BJDebugMsg ("All Done.")
            set TCount = 0
            set TOTAL = 0
        endif
    endfunction

    function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
        set T = CreateTimer()
        call BJDebugMsg("Timer Created")
        call TimerStart(T, 1.00, true, function timerLoop)
    endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent(gg_trg_Untitled_Trigger_001, Player(0), "-start", false)
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction

endscope

My problem is as follows: When calling TimerStart (timer, real, boolean, code handlerFunc) it is expecting a function. While within structures I am only using methods. Is there a simple solution for this?
 

Tyrulan

Ultra Cool Member
Reaction score
37
I understand that they are synonymous but I cannot do this without provoking a syntax error.

JASS:
call TimerStart(Timer, 1.00, true, method TimerLoop)
call TimerStart(Timer, 1.00, true, function TimerLoop)


Neither. I don't think anyway, suggestions?
 

Tyrulan

Ultra Cool Member
Reaction score
37
++Rep when I get a chance if it works. Thanks for the input.

EDIT: Alright, callback works fine, only if the handler function is a static method within my structure. Is that the way it has to be? Also, if it has to be static :( fine, how do I call attributes of my structure within that method? (timerLoop)
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Sorry, it is struct but not structure.

Struct is short name of structure.

But we use struct here instead of structure.
 

Tyrulan

Ultra Cool Member
Reaction score
37
Sorry, it is struct but not structure.

Struct is short name of structure.

But we use struct here instead of structure.

Yes, I know. That would seem obvious, no? However this is totally irrelevant to my problem. I'll get back to you all when I've checked out the timer utility.

EDIT: Okay, after some serious re-modeling and a few problems here and there I have been able to access my timer in the callback function. Here's a sample of my solution. The commands SetTimerData and NewTimer etc. are found within the TimerUtils library.

JASS:

set this.Timer = NewTimer()
call SetTimerData (this.Timer, this)
call TimerStart(this.Timer, 1.00, true, function thistype.timerLoop)


JASS:
 static method timerLoop takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local fishData fD = fishData(GetTimerData(t)) 
        //fishData is the name of my structure
        call BJDebugMsg ("Fish Type: " + fD.fishName)
endmethod


EDIT 2: Okay, so. The whole point of adding a timer was to avoid using TriggerSleepAction() but the timer doesn't seem to actually slow my code down any. How am I supposed to be using it? The timer is started and does it's periodic events but the rest of my trigger has already finished execution.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top