• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] About location leaks

Status
Not open for further replies.
Level 7
Joined
Aug 19, 2009
Messages
278
Hi guys..

Well i have a trigger where i need to use location a lot of times.
I remove the location after use like this

JASS:
        set loc1 = GetUnitLoc(rotatecenter[n])
        set z1 = GetLocationZ(loc1)
        set loc2 = GetUnitLoc(rotateunit[n])
        set z2 = GetLocationZ(loc2)
        call SetUnitFlyHeight(rotateunit[n], (150 + z1 - z2) , 0)
        call RemoveLocation(loc1)
        call RemoveLocation(loc2)

Some one said i could use a global location instead of a local location and use move location all the time it will work and i don't need to remove it

I don't think mui will be a problem. So which do you think will be more efficient.
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
It would look something like this:
JASS:
    globals
        location loc = Location(0, 0)
    endglobals
    
    function GetPointZ takes real x, real y returns real
        call MoveLocation(loc, x, y)
        return GetLocationZ(loc)
    endfunction
    
    function GetUnitZ takes unit u returns real
        return GetPointZ(GetUnitX(u), GetUnitY(u))
    endfunction
You would need to have Jasshelper to declare a global block like that and should probably make the global have a longer name to avoid conflicts.

EDIT:
@Spartipilo: He needs at least one location to get the z of stuff.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
A good way to handle locations is not using them, but rather use X/Y coordenates :) Avoid creating / destroying the location
 
Status
Not open for further replies.
Top