• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[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