HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[JASS] "code" as parameter....

05-30-2006, 03:43 PM#1
Sharingan
Collapse JASS:
TimerStart(timer whichTimer, real timeout, boolean periodic, code handlerFunc)
Somehow, i can't use functions with parameters as the "code-parameter"...
like:
call TimerStart(timer, 0.1, true, function bla(unit))
...
it would have to be :
call TimerStart(timer, 0.1, true, function bla) ...(a function without parameter)
Am i doing something wrong?
05-30-2006, 03:48 PM#2
The)TideHunter(
No, 'code' variable means it does not pass anything into the function.
If you want to pass something into the function you have to use the return bug and a gamecache

EDIT: I decided to show you how to do it, this is how you can do it:

This requires a gamecache called GC (or udg_GC in Jass)
Collapse JASS:
function GameCache takes nothing returns gamecache
    if(udg_GC == null) then
        call FlushGameCache(InitGameCache("GC"))
        set udg_GC = InitGameCache("GC")
    endif
    return udg_GC
endfunction

function H2I takes handle H returns integer
    return H
    return 0
endfunction

function I2Unit takes integer I returns unit
    return I
    return null
endfunction

function DoSomeAction takes nothing returns nothing
    local unit StoredUnit = I2Unit(GetStoredInteger(GameCache(), I2S(H2I(t)), "SomeDescriptionOrLabel"))
    // DO SOME ACTIONS
endfunction

function StartTimerNStuff takes unit whichUnit returns nothing
    local timer t = CreateTimer()
    call StoreInteger(GameCache(), I2S(H2I(t)), "SomeDescriptionOrLabel", H2I(whichUnit))
    call TimerStart(t, 10., flase, function DoSomeAction)
endfunction

EDITED: I forgot the () after CreateTimer
05-30-2006, 03:59 PM#3
Chuckle_Brother
a "code" variable is what is created when you go:
function FUNCTIONNAME
its used by timers, triggeraction additions and some other random things.
05-30-2006, 09:02 PM#4
Sharingan
Hmm, what i wanted to do is actually to implement "GetTriggerPlayer" into the "trigger_action" function, in which i have that
Collapse JASS:
call TimerStart(t, 10., flase, function DoSomeAction)
.
I can't write GetTriggerPlayer() into "DoSomeAction", since that function is "outside" of the event trigger...
05-30-2006, 09:14 PM#5
PipeDream
Yep, that's what TideHunter's post solves. You use the timer's handle as a unique ID to index the game cache, then store whatever you need in there.
05-31-2006, 04:39 AM#6
Sharingan
Hmm, now i see, thanks a lot!
05-31-2006, 09:22 AM#7
The)TideHunter(
In your condition, it would be:

Collapse JASS:
function GameCache takes nothing returns gamecache
    if(udg_GC == null) then
        call FlushGameCache(InitGameCache("GC"))
        set udg_GC = InitGameCache("GC")
    endif
    return udg_GC
endfunction

function H2I takes handle H returns integer
    return H
    return 0
endfunction

function I2Unit takes integer I returns unit
    return I
    return null
endfunction

function DoSomeAction takes nothing returns nothing
    local unit StoredUnit = I2Unit(GetStoredInteger(GameCache(), I2S(H2I(t)), "SomeDescriptionOrLabel"))
    // StoredUnit is now triggering unit from StartTimerNStuff function
endfunction

function StartTimerNStuff takes nothing returns nothing
    local timer t = CreateTimer()
    call StoreInteger(GameCache(), I2S(H2I(t)), "SomeDescriptionOrLabel", H2I(GetTriggerUnit()))
    call TimerStart(t, 10., flase, function DoSomeAction)
endfunction