• 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] explain handle?

Status
Not open for further replies.
Level 3
Joined
Aug 4, 2004
Messages
22
im pretty familiar with JASS and the only thing i dont know how to use are the types 'Handle'.

ive seen several people use them in thier spells but cant figure out why.

so my question(s) is,
what is the type 'Handle'
why is it useful?
when should it be used?

and if someone can give an easy to understand example please.
 
Level 3
Joined
Mar 27, 2004
Messages
70
All types except integer, real, boolean, string and code are handles.
For example:
JASS:
local unit u = GetTriggerUnit()
local handle h = u // Legal: All units are handles
set u = h // Illegal: Not all handles are units
The advantage of handles is that any object can be referenced assigned to a handle.
It can be inverted with a function like this:
JASS:
function HandleToUnit takes handle h returns unit
    return h
    return null
endfunction

function HandleToInt takes handle h returns integer
    return h
    return 0
endfunction
The HandleToInt function is great because you can get a unique integer representation for any object that way.
 
Level 3
Joined
Aug 4, 2004
Messages
22
ok, im still not sure on its uses?

i mean, why do you want/NEED to use handle?

can you always get away without using them?

can u give an exmaple where something would be impossible to do without the use of handle.
 
Level 2
Joined
Apr 13, 2004
Messages
29
You can completely avoid the type handle. It has no value by itself.
But on the other hand every unit, group, force, ... are actually handles since those types are derived from handle.
The only use I know of is using it with return bug functions so you do not need one for every type.
 
Level 3
Joined
Jul 17, 2004
Messages
57
i dont know exactly but i think u can use handlevars to have them as "local vars" between several fuctions because "normal" local vars work in only one
 
Status
Not open for further replies.
Top