Warcraft III resources & community, 2003–2006 · archived

Help : Pass local to function

9 posts
#1

Help : Pass local to function

Hi. I'm having a timer, which executes function. The problem is that the function needs a variable of type group. I can't pass parameters to function in timer. There has to be way to pass a local variable to function.

I can't use globals.
#2
Use Kattana's Handling system. Look into my Divine Intervention spell (yeah right...) and try to look for one timer. You should see some stuff like call StoreHandle() or GetLinkedUnit(). StoreHandle must be used like this:

StoreHandle(timer name, variable name, variable label).
Example: StoreHandle(t, cast, "cast")

The name of the timer is t, the name of the unit stored is cast and the label is "cast".

And when you want to get it, just go to the timer function and when you declare the locals:

local unit cast = GetLinkedUnit(GetExpiredTimer(), "cast")

~Daelin
#3
But in Divine I. the handler functions are other. There are for example GetLinkedUnit. Kattana's GetHandleHandle doesn't work for units. Can I use your handler functions? Or maybe there is a way for GetHandleHandle to work?


EDIT : No matter. I found it was the Vexorian's vars not Kattana. Kattana vars have SetHandleUnit functions.
#4
The scripts were given to me by someone else and that is why they look different from Vex/Kattana.

~Daelin
#5
But I'm stuck again. How to pass a unit group variable? There is no GetHandlerGroup function.


BTW in Site Discussions this guy said about Codeset Generator, the thing in the Tools section, not CDKey generator :)
#6
Too bad... He posted into the wrong section.

Copy the code from me and if you want to pass the unit do like this (btw... you will need to copy the codes which apply to the entire map which can be found in the trigger editor - click on the map icon on the left panel to find it into my map.

Take that script (ENTIRELY) and copy-paste it into your map. Now create a global variable called cache (CASE SENSITIVE) and which is Game Cache global. Ok, now to take the script, here is an example which work with a timer:



function Tim takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit cast = GetLinkedUnit(t, "cast")
call DisplayTextToForce( GetPlayersAll(), UnitId2StringBJ(GetUnitTypeId(cast)) )
set cast = null
set t = null
endfunction

function Main takes nothing returns nothing
local timer t
local unit cast
set cast = GetTriggerUnit()
set t = CreateTimer()
call StoreHandle(t, cast, "cast")
call TimerStart(t, 0.01, true, function Tim)
call TriggerSleepAction(1.00)
call Flush(t) //Needed to avoid further leaks. Use it before you destroy the timer/trigger etc.
call DestroyTimer(t)
set t = null
set cast = null


That should give you slight idea about using it with timers. With triggers situation is like this. I didn't make a real trigger but instead I gave it only an action. Put the event and condition you like.



function Trig takes nothing returns nothing
local unit cast = GetLinkedUnit(GetTriggeringTrigger(), "cast")
call RemoveUnit(cast)
set cast = null
call Flush(GetTriggeringTrigger())
call DestroyTrigger(t)
set t = null
endfunction

function Main takes nothing returns nothing
local unit cast
local trigger t
set cast = GetTriggerUnit()
set t = CreateTrigger()
call StoreHandle(t, cast, "cast")
call TriggerAddAction(t, function Trig)
set t = null
set cast = null



The linked units can also be used in condition function. ;)

~Daelin
#7
I tried, tried and I now understand it. Now to know about JASS as much as I need for now, question :

"What variables should be nullified, and what should be FlushHandleLocaled to prevent leaks???"
#8
FlushHandleLocals is a function that will remove all locals set using SetHandleHandle, SetHandleInt, SetHandleString or SetHandleBoolean. Just call it before destroying something that might have locals on it.

You should call it before destroying anything that has locals set on it.
You complained about there being no GetHandlerGroup function... it's called GetHandleGroup and it's used like this:

local timer t = GetExpiredTimer()
local group g = GetHandleGroup(t, "myGroup")


Daelin: It's not called the Handling system. It's called the Handle Vars or Local Handle Vars.
#9
Thanks KaTTaNa. And with SetHandlerGroup, it was the Vexorian's vars which didn't had it. Yours have it of course and I use them.