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

Help with when to use Call Destroy....(Udg_...)

Status
Not open for further replies.
Level 12
Joined
Jan 4, 2014
Messages
543
Hello friends,
I was wondering when I should use the Custom script call Destroy*whatever*(udg_*whatever*)
Should i destroy my variable at the end of every trigger that uses it or should I only destroy it once I have absolutely no more use for it.

Here is an example. I have this trigger where I want to give every unit in a unit group a tome, but I also have another bunch of triggers where i pick every unit in this same group and teleport them some place. So should I use the Custom script call to destroy my variable at the end of each of these individual triggers or only use it once I am no longer using this unit group?

Also on a similar note, if I make a custom spell where it uses temp points and temp unit, should I use this command every time the spell is cast, even though the spell will be cast multiple times?

Sorry if I am not clear, I am pretty new to this whole CustomScript call destroy thing.
 
Level 13
Joined
May 10, 2009
Messages
868
When you assign a value to a variable (unit group, points, etc), you're telling the game to reserve some memory ram which is going to store some information. When you don't need it anymore, use that command to let the game know when that memory should be freed.

Here's an example of one variable that is very useful and shouldn't be destroyed.

  • Game - Display to (All players) the text:
That (All players) is a player group variable:
JASS:
bj_FORCE_ALL_PLAYERS
Since you're going to use it for the rest of the game, there's no reason to destroy it. The same applies for your Unit Group variable.


Now, whenever you want to detect nearby units, do yours actions, and you won't need that group again. You must destroy it. There are 2 ways of doing that:

  • 1. Using the custom script: call DestroyGroup(udg_YourGroup);
  • 2. Assigning a value to another variable (bj_wantDestroyGroup), and positioning it on top of a Unit Group function.
Example 1:
  • Set point1 = (Position of (Triggering unit))
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Units within 300.00 of point1) and do (Actions)
    • Loop - Actions
      • Unit - Cause (Triggering unit) to damage (Picked unit), dealing 150.00 damage of attack type Spells and damage type Normal
  • Custom script: call RemoveLocation(udg_point1)
Example 2:
  • Set point1 = (Position of (Triggering unit))
  • Set group = (Units within 300.00 of point1)
  • Unit Group - Pick every unit in group and do (Actions)
    • Loop - Actions
      • Unit - Cause (Triggering unit) to damage (Picked unit), dealing 150.00 damage of attack type Spells and damage type Normal
  • Custom script: call DestroyGroup(udg_group)
  • Custom script: call RemoveLocation(udg_point1)
If I were to detect nearby units only for applying some damage once and nothing more, then I'd rather use first example. The second one you could use it if you needed to use the group multiple times. Like spells that cause damage with a projectile (shockwave). You'd need to check if a unit is NOT in a certain group, then damage and add it to the group. The next time the trigger loops, you will know that unit has been damaged and you shouldn't harm it again. When the shockwave ends, you destroy the group or clear it.

Also on a similar note, if I make a custom spell where it uses temp points and temp unit, should I use this command every time the spell is cast, even though the spell will be cast multiple times?

As for the points, yes, you will be fine. Also, because it's quite hard to know the next time you're going to use that same point again. That's why we remove it. Example:
  • Set point1 = (Position of (Triggering unit))
  • Set point2 = (point1 offset by 256.00 towards 270.00 degrees)
  • Special Effect - Create a special effect at point2 using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
  • Special Effect - Destroy (Last created special effect)
  • Custom script: call RemoveLocation(udg_point1)
  • Custom script: call RemoveLocation(udg_point2)
Concerning the unit, well, you can only remove it from the game.
  • Unit - Remove tmpunit from the game
Unless you're talking about doing this:
JASS:
set udg_tmpunit = null
Which is the same as:
  • Set tmpunit = No Unit
That wouldn't make any difference, because you're using a global variable. You'll be using it later with another unit, and setting it to null won't remove the unit from the game either.

Now, many people use a tmpunit variable in order to avoid calling a function many times in a row. For example:

  • Set caster = (Triggering unit)
  • Set point1 = (Position of caster)
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Units within 300.00 of point1) and do (Actions)
    • Loop - Actions
      • Set tmpunit = (Picked unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (tmpunit is Magic Immune) Equal to False
          • (tmpunit is A structure) Equal to False
          • (tmpunit is dead) Equal to False
          • (tmpunit belongs to an enemy of (Owner of caster)) Equal to True
        • Then - Actions
          • Unit - Cause caster to damage tmpunit, dealing 150.00 damage of attack type Spells and damage type Normal
          • Special Effect - Create a special effect attached to the origin of tmpunit using Abilities\Spells\Undead\AnimateDead\AnimateDeadTarget.mdl
          • Special Effect - Destroy (Last created special effect)
        • Else - Actions
  • Custom script: call RemoveLocation(udg_point1)
As you can see, I've used tmpunit multiple times. If I used (Picked Unit) instead of that variable, that would be a little bit bad, because I'd be calling a function many times. It's like calling you six times in a row and asking for the name of another person. Using a variable would be I writing down the name of a person somewhere, then reading it whenever I need it.


I hope I cleared things up a little bit for you.

EDIT: It looks like I flooded this page. lol
 
Last edited:
Status
Not open for further replies.
Top