• 🏆 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] Help : Pass local to function

Status
Not open for further replies.
Level 14
Joined
Nov 25, 2004
Messages
1,185
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.
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
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
 
Level 14
Joined
Nov 25, 2004
Messages
1,185
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.
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
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:

JASS:
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.

JASS:
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
 
Level 3
Joined
Mar 27, 2004
Messages
70
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:
JASS:
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.
 
Status
Not open for further replies.
Top