- Joined
- Sep 26, 2009
- Messages
- 9,534
This little snippet makes it so that you can handle all your timer data attaching stuff on one line and also release/get the timer data with just one line.
Instead of:
It becomes:
And with a timer that only expires once, you might normally do this:
It becomes:
It's also modular with structs to keep the code-length short and sweet:
Here's the short code:
Instead of:
JASS:
local timer t = NewTimer()
call SetTimerData(t, this)
call TimerStart(t, 2.00, false, function thistype.callback)
set t = null
It becomes:
JASS:
call TimerStart(NewTimerData(this), 2.00, false, function thistype.callback)
And with a timer that only expires once, you might normally do this:
JASS:
local timer t = GetExpiredTimer()
local thistype this = GetTimerData(t)
call ReleaseTimer(t)
set t = null
It becomes:
JASS:
local thistype this = PopExpiredTimer()
It's also modular with structs to keep the code-length short and sweet:
JASS:
method destroy takes nothing returns nothing
call ReleaseTimer(this.timer)
call this.deallocate()
endmethod
...
static method callback takes nothing returns nothing
call thistype(PopExpiredTimer()).destroy()
endmethod
...
static method create takes nothing returns thistype
local thistype this = thistype.allocate()
set this.timer = NewTimerData(this)
call TimerStart(this.timer, 2.00, false, function thistype.callback)
return this
endmethod
Here's the short code:
JASS:
library NewTimerData requires TimerUtils
globals
private timer t
private integer j
endglobals
function NewTimerData takes integer i returns timer
set t = NewTimer()
call SetTimerData(t, i)
return t
endfunction
function PopExpiredTimer takes nothing returns integer
set t = GetExpiredTimer()
set j = GetTimerData(t)
call ReleaseTimer(t)
return j
endfunction
endlibrary
Last edited: