Warcraft III resources & community, 2003–2006 · archived

how to pass between functions without Globals?

8 posts
#1

how to pass between functions without Globals?

ok well im trying to pass a unit from one function to another, but i dont want to use globals becuase this variable could be changed very frequently,

i also cant use it as arguments of the function becuse the function im passing it to is an added action to a created trigger.

so is it, and how, possible? use handles? how with handles if so?
#2
You should use local handle vars.

Like this:

local unit u = ... // parameter
call TriggerAddAction(trg, function SomeFunc)
call SetHandleHandle(trg, "LABEL", u)

function SomeFunc takes nothing returns nothing
    local trigger trg = GetTriggeringTrigger()
    local unit u = GetHandleUnit(trg, "LABEL")
    // Use u here..
endfunction
#3
ah i see now, thanks

one more thing in your exmaple, what about cleanup to avoid leaks?

like do i need DestroyTrigger(trg) at some point even if im not using local trigger trg=CreateTrigger()

what about leaks wit the handle? do i need to Destroy that at some poiint?
#4
When a unit dies (or decays) run FlushHandleLocals with the dying unit.
Like this:

call FlushHandleLocals(GetDyingUnit())

That cleans up the references (but not the objects).
Likewise, before destroying a handle, also call FlushHandleLocals with that so you don't leave any unnecissary entries in the gamecache.

If you are using a gg_trg_ trigger, you won't need DestroyTrigger.
If it is created on the fly, and you only want it to execute once, destroy it when it has executed. Like this:

call DestroyTrigger(GetTriggeringTrigger())
#5
Hmm... it doesn't seem to work into the spell I am making... Did you type the code correctly? I don't need to change anything about Handle stuff? I have no idea bout them...
#6
Those are Vexorians function Kattana!A true JASS cripter shouldn't use his Caster System!
#7
vicky2004Those are Vexorians function Kattana!A true JASS cripter shouldn't use his Caster System!


why vex is a noob?he uses KaTTaNa's handle vars,if you use sthing from another guy that doesnt supposed to mean you are noob
#8
vicky2004Those are Vexorians function Kattana!A true JASS cripter shouldn't use his Caster System!


Handle vars are kattana's , but the auto flushing thing is mine.

Handle vars are everyone's.

And the thing you said, no offense but that's stupid, utility functions exist for a reason, so true JASS scripters don't have to make stuff that was already done by other people so they have more time to make stuff that was not done yet.