• 🏆 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!

Destroy Rect?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
  • City Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: local integer i = 0
      • Custom script: local real x
      • Custom script: local real y
      • Set CitySpawn[0] = CITY000 <gen>
      • Set CitySpawn[1] = CITY001 <gen>
      • Set CitySpawn[2] = CITY002 <gen>
      • Set CitySpawn[3] = CITY003 <gen>
      • Set CityName[0] = Sparta
      • Set CityName[1] = Athens
      • Set CityName[2] = Larissa
      • Set CityName[3] = Thebes
      • -------- Turn Off Unit Index --------
      • Set UDexEnabled = False
      • -------- Create City --------
      • Custom script: loop
      • Custom script: exitwhen udg_CitySpawn[i] == null
      • Custom script: set x = GetLocationX(GetRectCenter(udg_CitySpawn[i]))
      • Custom script: set y = GetLocationY(GetRectCenter(udg_CitySpawn[i]))
      • Custom script: set udg_City[i] = CreateUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE), 'htow',x,y,0)
      • Custom script: call SetUnitUserData( udg_City[i], i )
      • Custom script: set i = i + 1
      • Custom script: endloop
      • -------- Turn ON Unit Index --------
      • Set UDexEnabled = True
Should I and could I destroy the variable CitySpawn after I'm done with it? I just use it to keep track of areas and spawn the city in beginning.
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
You can reassign global handle as many times as you want, just remember to destroy it if it's not needed anymore.

Well I dont want it; I want it destroyed! ^^

The information: udg_CitySpawn[0] == gg_rct_CITY000 becomes useless to me after setup since it makes no difference if i use GetUnitLoc or GetRectCenter.

While we are at it.

  • MainSetup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Turn OFF Unit Index --------
      • Set UDexEnabled = False
      • -------- RUN SETUP --------
      • Trigger - Run Setup Buildings <gen> (checking conditions)
      • Trigger - Run Setup City <gen> (checking conditions)
      • Trigger - Run Setup Player <gen> (checking conditions)
      • -------- Turn ON Unit Index --------
      • Set UDexEnabled = True
      • Custom script: call DestroyTrigger(GetTriggeringTrigger())
JASS:
 call DestroyTrigger(GetTriggeringTrigger()) // Should this line be added after all Setup Triggers? How do you do it?

Also while we are at it, how to purge setup triggers?
 
Last edited:
Level 15
Joined
Aug 7, 2013
Messages
1,337
For triggers you should only destroy them once you know you will never need to run them again. Once the trigger is destroyed, it won't work again unless you dynamically re-create it.

If you trigger just is one time event, you can put that line as the very last statement in the action.

e.g.

JASS:
function main takes nothing returns nothing
  //your code here
  ...
  //now destroy the trigger
  call DestroyTrigger(GetTriggeringTrigger())
endfunction

Alternatively, if the trigger is stored in a global trigger variable, then you can destroy it any time, but once you do, that trigger is gone for good.

In order to remove rects, you can just call

JASS:
call RemoveRect(myRect)

Note again, once you do that, myRect won't work for any functions that use rects as it no longer exists.

In general, unless you have heavy optimization concerns, having a few leaks here and there won't cause any difference. What is really important is when you have functions that generate local handles, that those handles must be destroyed/reclaimed at some point, otherwise WC3 will progressively use more and more memory, until the map is unplayable.

It doesn't appear you are dynamically generating triggers or rects, so I wouldn't lose much sleep over this.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
That would still leak the triggeraction, IIRC. If you're aiming for memory cleanup, use triggercondition for setups instead.

Also, don't forget to null both CitySpawn[index] and gg_rct_CITY00x after destroying the handle it points to or else all your work is for nothing lol.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Peanuts. You only run the init trigger once and do not recreate the trigger. Destroying some static remains and especially globals is more prone to cause complications while development.

GetUnitLoc/GetRectCenter creates a new location btw. You can also use GetRectCenterX/Y.

edit: new location, not rect of course
 
Last edited:
Level 15
Joined
Aug 7, 2013
Messages
1,337
GetUnitLoc creates a new rect or a new location? I always thought it returned a location.

JASS:
local unit u = CreateUnitAtLoc('hfoo', ...)
local location footmanLoc = GetUnitLoc(u)
 
Status
Not open for further replies.
Top