| 10-23-2007, 12:07 AM | #1 |
Hi~ I got a few questions about them. I've heard that using X, and Y, Coordinates in place of JASS:local location x = GetUnitLoc() Also, if you do JASS:local real x = GetLocationX(GetUnitLoc()) Finally, how do you get the Z coordinate of a location? |
| 10-23-2007, 12:36 AM | #2 |
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 JASS:local location p = GetUnitLoc() local real x = GetLocationX (p) then yes. |
| 10-23-2007, 12:45 AM | #3 |
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 |
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 |
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 |
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 |
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 | |
Quote:
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 | |
Quote:
Actually in his example he does need to clean up the location. And just to clarify so you don't get any misconceptions: JASS:local real x = GetLocationX(GetUnitLoc()) |
| 10-23-2007, 11:37 AM | #10 |
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 |
blu_da_noob: Sorry, that's what I meant. |
| 10-24-2007, 10:27 AM | #12 | |
Quote:
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 :) |
