• 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] 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