• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] how to pass between functions without Globals?

Status
Not open for further replies.
Level 3
Joined
Aug 4, 2004
Messages
22
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?
 
Level 3
Joined
Mar 27, 2004
Messages
70
You should use local handle vars.

Like this:
JASS:
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
 
Level 3
Joined
Aug 4, 2004
Messages
22
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?
 
Level 3
Joined
Mar 27, 2004
Messages
70
When a unit dies (or decays) run FlushHandleLocals with the dying unit.
Like this:
JASS:
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:
JASS:
call DestroyTrigger(GetTriggeringTrigger())
 
Level 12
Joined
Mar 11, 2004
Messages
600
vicky2004 said:
Those 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.
 
Status
Not open for further replies.
Top