HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Timer Help

01-19-2007, 01:34 AM#1
Here-b-Trollz
New here.

How exactly can I associate a local variable with a function called by a timer?

Example:
Collapse JASS:
function LifeDegrade_SetLife takes unit a returns nothing
    local timer b
    call SetUnitState( a, UNIT_STATE_LIFE, GetUnitState(a, UNIT_STATE_LIFE) - udg_LifeDegradeRate)
    call TimerStart( b, udg_LifeDegradeRate, false, LifeDegrade_SetLife)

    ...

I would like to be able to recycle unit a in this function as unit a again after the timer expires, so that this can be run efficiently on multiple units simultaneously. I heard something about using GameCache, but it really isn't clear to me . Help please?
01-19-2007, 01:44 AM#2
Rising_Dusk
Try Here.
01-19-2007, 03:39 AM#3
Here-b-Trollz
That is the first place I looked, but I don't understand. When you use:

Collapse JASS:
call StartTimer( MyTimer, Interval, false, *functioncalled*)

do you put the arguments for *functioncalled* in like this?
Collapse JASS:
call StartTimer( MyTimer, Interval, false, *functioncalled(unit)*)
01-19-2007, 03:56 AM#4
PipeDream
*cough* vex, closures plz k thx
01-19-2007, 12:13 PM#5
Rising_Dusk
Collapse JASS:
call StartTimer( MyTimer, Interval, false, *functioncalled(unit)*)
That would not parse.
You cannot pass arguments through the timer callback function.

It would work ONLY like this --
Collapse JASS:
call StartTimer( MyTimer, Interval, false, function MyFunctionRawr)
Then you would need to use one of the... 4ish methods discussed in the tutorial to move variables from the initial function to the callback.
Game cache, special attachments, globals, whatev'.