Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
HA, my friend you have the most comon problem every1 has - you can't.
You can only use Globals to store values between functions.
However, for locals, there are systems, like vJASS, Katana's handle vars, CSCache, using cache, and many, many other things.
You have no choice but to study them :s
Well, my advice is - download Jass new Gen pack at wc3 campaign.
Then use a system like ABC (i use it, maybe I can help you learning it).
However, there is another way, that is slower however - using cache.
Getting that jass newgen also allows for global blocks, so that you can declare global variables outside of the variable editor.
For passing data between functions, if I'm not using any delays or anything, I'll often use bj_Variables in the place of creating new globals. No idea if that really helps in any considerable amount though
Handle Variables are quite simple.
I will give some simple pointers.
A handle is an object - unit, location, unitgroup, playerforce, timer,triger etc.
When you attach a variable to an object(the most common thing is attaching to timers)
you use something like call SetHandleReal(a,"b",c)
I will put a example situation
t is timer.
q is a unit.
To attach a variable to something it must be initialized (likeCreateTimer(), GreateGroup() and etc).
Simple code would look like this
JASS:
local timer t = CreateTimer()
local unit q=GetTriggerUnit() // for example
call SetHandleUnit(t,"UNIT_TO_DAMAGE", q)
call TimerStart(t,1,true,damage)
Now when damage function is called(every second) use
JASS:
local unit u=GetHandleUnit(GetExpiredTimer(),"UNIT_TO_DAMAGE")
call SetUnitState(u,UNIT_STATE_LIFE,GetUnitState(u,UNIT_STATE_LIFE) - 20)
Thus making the unit loose 20 hp
When you are done with an attached handle/variable you should use FlushHandleLocas(t).
SetHandleTYPE(a,b,c)
The Type specifies what you are attaching(types are (for this) Integer, Real, Boolean, string and Handle)
a is the handle to which you are attaching.
b is a string - like a name
c is the variable/value you are attaching
GetHandleType(d,e)
Types here are more: Handle, Integer, Real, Boolean, Unit, String, Timer, Trigger, Effect, Lightning, Widget and Group)
e is the name
FlushHandleLocals(f)
f is a handle.
This deletes all attached things to f.
Just a pointer
And note that Handle Variables are far more simpler than ABC as it is a struct attaching system so you must first study structs(not that hard either).
Yah, I've read some tutorials about teh pointers, but thanks for taking the time to simplify it further + rep to all posters, you all gave me some info (altho I have to spread the rep around a bit... damnit)
Hm, forgot to mention something.
About leaks.
You null all the local variables/handles normally(after you have attached them to something).
Then, when all done with some variable/handle you Remove/Destroy it the normal way and then null it.
A more compleate version covering leaks:
JASS:
local timer t = CreateTimer()
local unit q=GetTriggerUnit() // for example
call SetHandleUnit(t,"UNIT_TO_DAMAGE", q)
call SetHandleInt(t,"count",0)
call TimerStart(t,1,true,damage)
set q=null
set t=null
JASS:
function damage takes nothing returns nothing
local timer t=GetExpiredTimer()
local unit u=GetHandleUnit(t,"UNIT_TO_DAMAGE")
local integer i=GetHandleInt(t,'count")
call SetUnitState(u,UNIT_STATE_LIFE,GetUnitState(u,UNIT_STATE_LIFE) - 20)
set i=i+1
if (i>10) then
call FlushHandleLocals(t)
call PauseTimer(t)//ain't sure of syntax
call DestroyTimer(t)
else
call SetHandleInt(t,"count",i)
endif
set unit=null
set t=null
endfunction
Note that a normal damaging over time action would require an attached damaging unit Handle.
If you want to pass a variable to another function... just use it as a parameter. xD
JASS:
function Two takes unit someUnit returns nothing
call DoSomethingFunky(someUnit)
// Do other stuff here...
endfunction
function One takes nothing returns nothing
local unit u = CreateUnit(Player(0), 'hpea', 0.0, 0.0, 0.0)
// Do stuff here...
call Two(u)
// omglul
endfunction
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.