• 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] Struct-related location question

Status
Not open for further replies.
Level 4
Joined
Apr 2, 2006
Messages
32
Say I have a struct similar to the following with some location members:
JASS:
struct somestruct
    location l1
    location l2
    location l3
endstruct
...would destroying the struct and not using "call RemoveLocation(...)" clean the locations after being used?

Or would they still cause leaks and require the remove function?
 
Level 11
Joined
Feb 18, 2004
Messages
394
destroying a struct destroys the struct, not any of its member variables.

structs can have an onDestroy method which will be called when a structs .destroy() method is called, but before the struct is actually destroyed.

eg:
JASS:
struct somestruct
    location l1
    location l2
    location l3
    
    method onDestroy takes nothing returns nothing
        call RemoveLocation(this.l1)
        call RemoveLocation(this.l2)
        call RemoveLocation(this.l3)
    endmethod
endstruct

Also, don't use locations. For every function which uses a location, there is an equivalent (or pair of equivalent) functions which use real x / y coordinates. You don't have to create or destroy or null real-type values, so using coordinates is preferred for everything. (There are two functions that do not have x / y counterparts: GetSpellTargetLoc() and GetLocationZ(someLoc))

Use the function finder in NewGen's trigger editor. It can greatly help in quickly finding the functions you need. (Hold down CTRL and click a function name to bring up the function finder showing that functions definition.)

Edit: Forgot this.
 
Level 14
Joined
Nov 20, 2005
Messages
1,156
GetLocationZ(someLoc) can be replaced with this:

JASS:
function GetPointZ takes real x, real y returns real
    call MoveLocation(PermaLocation, x, y)
    return GetLocationZ(PermaLocation)
endfunction

And that is faster than creating and destroy a location each time.
 
Status
Not open for further replies.
Top