JASS: Handles & anything

Dois

New Member
Reaction score
1
So what are Handles and Widgets and stuff related to that?

I've read through the basic JASS tutorials and they don't explain what they are... What are they for etc?

Anyone? Thanks...

Edit: Also, you know how you "custom script: call RemoveLocation(udg_Whatever_Point)"

But if you're writing it in JASS and you use a local variable for location, do you need to destroy at the end as well? like do the contents gets stuck in the memory or whatever liike in GUI

Edit Again: Another thing...

JASS:
function Armageddon_Conditions takes nothing returns boolean
    if GetSpellAbilityId() == 'A003' then
        return true
    endif
    return false
endfunction
is the same as
JASS:
function Armageddon_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A003' ) ) then
        return false
    endif
    return true
endfunction
Right? and would the first one be considered an optimized version of the 2nd one?
 

Dois

New Member
Reaction score
1
well ok.. but can u give me examples of what are considered objects?

thankss

edit:

Code:
 return GetSpellAbilityId() == 'A003'

can you do that because "==", "!=", "<=", ">+" (Those are called "comparisons" right?) return boolean values? (at least thats what I've found out... I think...)
 
Reaction score
333
Every variable aside from integers, booleans and reals references an object.

can you do that because "==", "!=", "<=", ">+" (Those are called operators right?) return boolean values? (at least thats what I've found out... I think...)

Yes.
 

Dois

New Member
Reaction score
1
ok thanks man

edit: just wondering... do you say "boo-lean" or "boo-lee-yen" or are they both correct

edit again: and if anyone there is listening... whats the smallest value for TriggerSleepAction(X)?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> ... use a local variable for location, do you need to destroy at the end as well?

Local variables are always destroyed at the end of the function.
No matter what.
It's the content you need to take care of.

local group g

Now you have a variable, of type "group".
It can not be used yet.
If the function were to end now, the variable would be destroyed. End of story.

local group g = CreateGroup()

Same deal. Only, a new handle has been created and assigned.
The variable can be used now.

g -> group

For example with:
call GroupAddUnit(g, GetTriggerUnit())

g -> group -> unit

The handle "g" points to a group, that group holds some units.
If the function ends now, g is gone.
The content not. Memory leak.

call DestroyGroup(g)

The content is gone.
But:

g -> group

It doesn't hold anything usable anymore, but there's still the reference to the group handle.

set g = null

The reference is gone too.
The function may end.



That's also the reason why integers for example don't need any care.
They do not point to some created information, they simply are the information.
 

Dois

New Member
Reaction score
1
thank you. a lot

but still...

if g>group

then local integer i = 1

i>1? is it or i>integer>1

or im still not complete clear...

uhh

why do you have to null "g"? i thought theyre always destroyed... looks like im still not completely clear about handles... ill try to keep reading ur post until i fully understand

like uhh what if you did all that again but with "local location L"?

>Same deal. Only, a new handle has been created and assigned.
The variable can be used now.

The handle is "g"? not the "group"?

there are 3 things now right?

the variable "g", the group and the units in it?

Which ones the handle? (and if u know why, why do they call it a handle?" and uhh the content is the units right?)
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
local integer i = 42

The variable is "i", its type is "integer", and the content is 42.
Nothing to worry there.


local group g = CreateGroup()
call GroupAddUnit(g, <some unit>)

The variable is "g", its type is "group", and the content is the created group.
The group, in turn, points to its own content, the units it holds. (Optionally, the group may be empty, but that doesn't change anything on g)

Since the content is created, g is a handle. A handle of type group, but a handle still.

You can add or remove units to the group.
g does not care about it.
g holds the reference to the created goup. It's the group's job to deal with the unit is has.

g -> group -> units

When you destroy the group, both the units and the group are gone.
But, what happens to g?
Well, g still has some value. The same reference it had before.
You can not use the group anymore, but no one told g yet...
Now, when the function ends, g, being local, will be destroyed.
And the reference it was holding? What happened to it? That's the problem. No one told it yet that it is not needed anymore.
That's what "set g = null" is doing.



Locations work the same way.

local location l = GetUnitLoc(GetTriggerUnit())

This creates a new location, stores the unit's position in it, and... the returned newly created handle ends up in l.

l -> location -> x,y

Removing the location will get rid of the point, and the location as such.
But, yet again, no one told l yet that its reference is not needed anymore.
Hence the required
set l = null



g is a handle, the group is an object.
l is a handle, the location is an object.
The types are basically there so you can't "set g = l"... which might lead to rather weird results or crashes.
 

Dois

New Member
Reaction score
1
ok now i really get it when he said "A handle stores a reference to an object"

btw, why do you have to do local group g = CreateGroup()

can you do

JASS:
local group g
set g = CreateGroup


Not that its better or anything... as a matter of fact its worse right?... just wondering if u can do that and if u cant, why?

Edit agaiN: btw, you don't need to null globals cuz they're not local right? when you use them again they're overwritten? and when you "call DestroyGroup(asd)", the contents you are destroying is the GROUP and the units in the group right? meaning the group itself is considered content?
 

Dois

New Member
Reaction score
1
ok thanks... also... so handles are kinda like... the same as variables right? juz that they point to something and variables (integer and stuff) are "themselves" or... whatever way you use to describe them...
 

soulreaping

New Member
Reaction score
17
Handles are type of variables.

You declare a variable of type handle when you write this for example:
JASS:
local handle h


Then you can assign any handle value to the newly created handle variable (units, items, destructables etc.).
 

Cohadar

master of fugue
Reaction score
209
Handles are type of variables.

You declare a variable of type handle when you write this for example:
JASS:

local handle h


Then you can assign any handle value to the newly created handle variable (units, items, destructables etc.).

Ok people never do this, it is bad for so many reasons that I simply don't care to explain.
 

soulreaping

New Member
Reaction score
17
Hey, I never said "use it" he asked if handles are type of variables, I said yes and made a "proof" as you declare them like integers, reals, booleans etc. so it is a type of variable.

I myself never define a variable of type handle I never found it a good use for me.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top