HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

X, Y, Coordinates

10-23-2007, 12:07 AM#1
Monky-Master
Hi~
I got a few questions about them.

I've heard that using X, and Y, Coordinates in place of
Collapse JASS:
local location x = GetUnitLoc()
is a lot faster. Is that true? Also, why?

Also, if you do
Collapse JASS:
local real x = GetLocationX(GetUnitLoc())
Do you have to clean up the location where you get your point?

Finally, how do you get the Z coordinate of a location?
10-23-2007, 12:36 AM#2
Anopob
X and Y is faster than locations. Don't ask ME why, it just is. You do not need to clean leaks for reals, integers, booleans and strings. However, you do need to clean up locations or whatever else if you use them.

Sorry but I don't know about Z.

EDIT: Actually, in you example, you do not need to clean up that location. But if you do
Collapse JASS:
local location p = GetUnitLoc()
local real x = GetLocationX (p)

then yes.
10-23-2007, 12:45 AM#3
Monky-Master
Oh, I see, well, I'll just wait for someone to explain the other stuff for me.

Thanks btw.
10-23-2007, 12:48 AM#4
PipeDream
It's not generally true that it's faster. x,y is faster because creating a handle is slow, location is faster because indirection lets you pass one argument instead of two. Indirection causes a host of problems though so using x,y whenever possible is a safe bet.
10-23-2007, 12:48 AM#5
moyack
Using the X, and Y coordinates is much better than locations because X and Y are real variables and they don't need to be destroyed, and because they are not handles like the location, they're faster (at least to code :P).

About this: local real x = GetLocationX(GetUnitLoc()), it can be replaced by: local real x = GetUnitX(Unit)
10-23-2007, 12:52 AM#6
Monky-Master
Oh, thanks moyack, I guess that answers a part of the question.

so if I did local real x = GetUnitX(Unit), could I sub Unit with a location variable?
10-23-2007, 12:54 AM#7
Ammorth
no, you would use the unit directly. This makes it so you don't have to create a location to get the position of a unit.
10-23-2007, 01:02 AM#8
moyack
Quote:
Originally Posted by Monky-Master
could I sub Unit with a location variable?
No, you can't. I mean this:

Collapse JASS:
function LongCode takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local location l = GetUnitLoc(u)
    local real x = GetLocationX(l)
    local real y = GetLocationY(l)
    // your stuff here...
    call RemoveLocation(l)
    set l = null
    set u = null
endfunction

function ShortCode takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    // your stuff here...
    set u = null
endfunction

Both functions do exactly the same, but the first one use a location and the other don't use it. As you can see, GetUnitLoc(u) can be skipped and you gain by reducing the code length.
10-23-2007, 08:28 AM#9
blu_da_noob
Quote:
EDIT: Actually, in you example, you do not need to clean up that location.

Actually in his example he does need to clean up the location. And just to clarify so you don't get any misconceptions:
Collapse JASS:
local real x = GetLocationX(GetUnitLoc())
The GetUnitLoc() returns a location. You never destroy the location (and can not, as you have no reference to it, unless the function you call on it destroy the location which is passed to it) and thus the location leaks.
10-23-2007, 11:37 AM#10
cohadar
There is one thing unanswered here, it is about the Z

There is a function GetLocationZ(loc)
but it does not return the Z of location,
locations don't have Z, they have only X,Y
(that is why there is no SetLocationZ function)

GetLocationZ actually returns the Ground height at Point X,Y
10-23-2007, 08:00 PM#11
Anopob
blu_da_noob: Sorry, that's what I meant.
10-24-2007, 10:27 AM#12
Silvenon
Quote:
Originally Posted by cohadar
(that is why there is no SetLocationZ function)

What do you mean? There's no SetLocationX/Y also. Did you mean SetUnitZ?

Yeah, that function is bad, because you still have to use locations if you want to calculate terrain height, makes me wonder why there's no GetPointZ or something. GetSpellTargetLoc is also annoying :)