• 🏆 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] Destroying local variables?

Status
Not open for further replies.
Level 2
Joined
Feb 14, 2020
Messages
19
Hello!

I dont think I will need JASS for much but local variables would be a god send. However, am I dealing with the aftermath correctly?

This is a simple movement system for a TD.
  • Movement P1
    • Events
    • Conditions
    • Actions
      • Custom script: local location loco
      • Custom script: local unit enteringUnit
      • Custom script: set enteringUnit = GetEnteringUnit()
      • Custom script: call SetUnitUserData(enteringUnit, ( GetUnitUserData(enteringUnit) + 1 ))
      • Custom script: set loco = GetRandomLocInRect(udg_regions_P1[GetUnitUserData(enteringUnit)])
      • Custom script: call IssuePointOrderLoc(enteringUnit, "move", loco)
      • Custom script: set loco = null
      • Custom script: set enteringUnit = null
      • Custom script: call RemoveLocation(loco)
      • Custom script: call RemoveUnit(enteringUnit)
My coding experience say that nulling them should be enough, but eh, you never know..
The last line, by definition, does nothing as the variable has been nulled, should I use DestroyUnitPool instead?

Thanks in advance!
 
Level 2
Joined
Feb 14, 2020
Messages
19
You need to remove the location before setting loco to null. The way you’re doing it now is trying to remove a null location, which does nothing. Nothing needs to be done to the unit (unless you actually intend it to be removed), as they are handled naturally by the game.

Also, locals can be used in GUI with this trick: local udg_

Destroy first, null after. Gotcha.
Thanks a lot.

That map actually covered everything I was gonna ask about leaking locals, thanks for linking to it.
I am a bit concerned though about locals in GUI. Isn't that something that can or may be patched? I dont mind JASSing myself through triggers, just wish they had proper documentation.

EDIT:

Lets say I wanna use the same local variable in the same trigger, do I only destroy or destroy AND null?

ex.
1. Declare local point
2. Set local point
3. Use local point
4. Remove local point
5. Null local point
6. Set local point
7. repeat 4+5
 
Last edited:

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,891
EDIT:

Lets say I wanna use the same local variable in the same trigger, do I only destroy or destroy AND null?

ex.
1. Declare local point
2. Set local point
3. Use local point
4. Remove local point
5. Null local point
6. Set local point
7. repeat 4+5
You only null at the end:
1. Declare local point
2. Set local point
3. Use local point
4. Remove local point
5. Set local point
6. Use local point
7. Remove local point
8. Null local point
 
Status
Not open for further replies.
Top