• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Simple Timer Recycler v1.0

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
  • Like
Reactions: deepstrasz
  • JASS:
    //*************************************************************************************
    //*
    //*    Simple Timer Recycler by Almia
    //*
    //*************************************************************************************
    //*
    //*    Simple Timer Recycling and Timer Indexing
    //*
    //*    Created for OaD2
    //*
    //*************************************************************************************
    //*
    //*    API
    //*
    //*    function GetRecycledTimer takes nothing returns timer
    //*    function GetTimerData takes timer t returns integer 
    //*    function RecycleTimer takes timer t returns nothing
    //*
    //*************************************************************************************
    function GetRecycledTimer takes nothing returns timer
        local integer i = udg_TR_RC[0]
        if 0 == i then
            if null == udg_TR_Hash then
                set udg_TR_Hash = InitHashtable()
            endif
            set i = udg_TR_C + 1
            set udg_TR_C = i
            set udg_TR_Timers[i] = CreateTimer()
            call SaveInteger(udg_TR_Hash, GetHandleId(udg_TR_Timers[i]), 0, udg_TR_C)
        endif
        set udg_TR_RC[0] = udg_TR_RC[i]
        return udg_TR_Timers[i]
    endfunction
    
    function GetTimerData takes timer t returns integer 
        return LoadInteger(udg_TR_Hash, GetHandleId(t), 0)
    endfunction
    
    function RecycleTimer takes timer t returns nothing
        local integer i = GetTimerData(t)
        call PauseTimer(t)
        set udg_TR_RC[i] = udg_TR_RC[0]
        set udg_TR_RC[0] = i
    endfunction
  • Demo:
    JASS:
    constant function Chars takes nothing returns string
        return"abcdefghijklmnopqrstuvwxyz"
    endfunction
    
    function PrintLoop takes nothing returns nothing
        local integer i = 5
        local integer sl = StringLength(Chars())
        local integer s
        local timer t = GetExpiredTimer()
        loop
            exitwhen i == 0
            set s = GetRandomInt(0, sl - 1)
            call BJDebugMsg(SubString(Chars(),s , s + 1))
            set i = i -1
        endloop
        call BJDebugMsg("TimerData : " + I2S(GetTimerData(t)))
        call RecycleTimer(t)
    endfunction
    
    function InitTrig_Demo takes nothing returns nothing
        call TimerStart(GetRecycledTimer(), 1.0, true, function PrintLoop)
        call TimerStart(GetRecycledTimer(), 0.75, true, function PrintLoop)
        call TimerStart(GetRecycledTimer(), 0.5, true, function PrintLoop)
        call TimerStart(GetRecycledTimer(), 0.25, true, function PrintLoop)
    endfunction
Contents

Simple Timer Recycler v1.0 (Map)

Reviews
13:41, 8th Jun 2013 Magtheridon96: No. Just No. Seriously.

Moderator

M

Moderator

13:41, 8th Jun 2013
Magtheridon96: No. Just No. Seriously.
 
Level 10
Joined
Aug 21, 2010
Messages
316
Can you show an example that uses GetTimerData()? The one you posted will show a message displaying the data, but a user won't know how to actually use it meaningfully.

It is like when a teacher assigns you to use the word "sesquipedalian" in a sentence, and you write "I like the word sesquipedalian".

:)

99% of people know how to use this.There's nothing special, nothing new.We saw something like this a million times
 
Top