MethodTimer - Useful?

Reaction score
341
Most likely it wouldn't get approved and you are probably better off using a static method + indexing (which this is a wrapper for).
The only reason I would think it's useful, is because people are always asking why they can't use methods inside timer callbacks.

Anyways, MethodTimer allows you to simulate methods inside timer callbacks. So you could do something like..

JASS:
scope MethodTimerTest

    private struct data
        timer t = CreateTimer()
    
        method displayIndex takes nothing returns nothing
            call BJDebugMsg(I2S(this)) // Displays 1 every second
        endmethod
        
        static method onInit takes nothing returns nothing
            local data d = data.create()
            call thistype.displayIndexPeriodic(d.t, 1.00, true, d)
        endmethod
        
        //! runtextmacro METHOD_TIMER("displayIndex")
    endstruct

endscope


The only rule is the textmacro has to be below the method AFAIK.
Placing it at the bottom of the struct would be fine.

Here's the script code...

JASS:
library MethodTimer
    
    globals
        public hashtable HASH = InitHashtable()
    endglobals
    
    //! textmacro METHOD_TIMER takes FUNC_NAME
        static method MethodTimer_call_$FUNC_NAME$ takes nothing returns nothing
            call thistype(LoadInteger(MethodTimer_HASH, GetHandleId(GetExpiredTimer()), 0)).$FUNC_NAME$()
        endmethod
        
        static method $FUNC_NAME$Periodic takes timer t, real timeout, boolean periodic, integer index returns nothing
            call SaveInteger(MethodTimer_HASH, GetHandleId(t), 0, index)
            call TimerStart(t, timeout, periodic, function thistype.MethodTimer_call_$FUNC_NAME$)
        endmethod
    //! endtextmacro
    
endlibrary


EDIT: erm, now that I look at it it's crap.
 

weaaddar

New Member
Reaction score
6
I'm pretty sure zincs anonymous methods actually already do what you want...
[ljass]TimerStart(mytim,0,false,method(){BJDebugMsg(I2S(this));});[/ljass]
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
> I'm pretty sure zincs anonymous methods actually already do what you want...

To be honest, Zinc is kinda lame, IMO.
I don't like the syntax at all.
 
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