• 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!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] How do you effectively move a variable from one function to another?

Status
Not open for further replies.
Level 6
Joined
Jul 25, 2005
Messages
221
How do you effectively move a variable from one function to another without using the variable editor to create one?

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

For this purpose i recommend that you read this tutorial - the best tutorial about spells and cache that i've ever seen.
http://www.wc3campaigns.net/showthread.php?t=83337

Hope it helps ...
rep++ =P
 
Level 2
Joined
May 21, 2007
Messages
14
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
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
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).
 
Last edited:
Level 6
Joined
Jul 25, 2005
Messages
221
Yah, I've read some tutorials about teh pointers, but thanks for taking the time to simplify it further :D + rep to all posters, you all gave me some info (altho I have to spread the rep around a bit... damnit) :cute:
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
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.
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
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
 
Status
Not open for further replies.
Top