HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Attaching 'code' variable

04-01-2006, 08:20 PM#1
TaintedReality
Using the handle functions, can I attach a code variable to something (a timer in this case)? Or maybe using tables or something else?

Edit: Woot, found a way to work around it, since the handle vars don't work with code variables. In case anyone's interested:
In my function I had certain events happen when the spell was cast, then a timer started which moved an object towards the target. When the object hit the target, I wanted a function to be run, which is the code variable. My problem was I couldn't find a way to get the code parameter from the first function into the handlerFunc for the timer.

What I did was create a second timer whose handlerFunc was the code parameter of that function. I set the timeout very low, almost instant, then right after it was created paused the timer. I then attached this timer to my first timer, so I could get it back later. Now when the object hits the target, I can simply use ResumeTimer() and the function will happen pretty much immediately. Haven't actually tested it yet..but it seems sure to work after some messing around.
04-01-2006, 08:48 PM#2
Anitarf
You could also attach the function name as a string to your first timer and then use ExecuteFunc() to run it.
04-01-2006, 09:34 PM#3
karukef
You can also attach a trigger. Just create a trigger, add your desired function as an action of that trigger, then attach the trigger, and retreive it/run it later on.

I've used this for a system that automatically launches triggers whenever an ability is added to/removed from/used by a hero, and it's very intuitive.
04-01-2006, 11:37 PM#4
TaintedReality
Ah thanks, using ExecuteFunc will be simpler, and I won't have to mess around with the timers so much.

Edit: One problem, now I can't get any variables from function to function. I'll have to stick with timers or triggers.
04-02-2006, 04:01 AM#5
karukef
You can pass variables to functions that "take nothing" using global variables or gamecache. I personally think gamecache is the easiest and most readable way of doing it.

Collapse JASS:
call StoreString(udg_cache, "your_funcname", "some_string_arg", "just a test")
call StoreInteger(udg_cache, "your_funcname", "some_integer_arg", 71)

call ExecuteFunc("your_funcname")

function your_funcname takes nothing returns nothing
    local string s = GetStoredString(udg_cache, "your_funcname", "some_string_arg")
    local integer i = GetStoredInteger(udg_cache, "your_funcname", "some_integer_arg")

    //Do stuff
endfunction
04-02-2006, 05:03 AM#6
TaintedReality
I just used the timer method, with handle vars. Works perfectly.
04-03-2006, 11:40 AM#7
BertTheJasser
Quote:
Originally Posted by karukef
You can also attach a trigger. Just create a trigger, add your desired function as an action of that trigger, then attach the trigger, and retreive it/run it later on.

I've used this for a system that automatically launches triggers whenever an ability is added to/removed from/used by a hero, and it's very intuitive.

Thats worse than the usage of a timer, because you always must get rid of the triggeraction. All in all I prefer the >call ExecuteFunc("funcname")<.
04-03-2006, 12:29 PM#8
Vexorian
blerg

Collapse JASS:
function C2I takes code c returns integer
    return c
    return 0
endfunction


function I2C takes integer i returns code
    return i
    return null
endfunction

04-03-2006, 10:38 PM#9
TaintedReality
Oh. That was easy enough, I thought I was being all tricky with the timer thing but I guess not =P.