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

Is this trigger leaks? I don't get it

Status
Not open for further replies.
Level 17
Joined
Jun 2, 2009
Messages
1,123
Hello everyone. I have checked the post Things That Leak but i don't understand one thing.

  • Hunting Shade Loop
    • Events
      • Time - Every 6.00 seconds of game time
    • Conditions
    • Actions
      • Set TempLoc = (Position of u_FacelessHunter)
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within 750.00 of (Position of u_FacelessHunter) matching ((((Matching unit) belongs to an enemy of (Owner of u_FacelessHunter)) Equal to True) and (((Matching unit) is in HerolarALL) Equal to True))) and do (Actions)
        • Loop - Actions
          • Unit - Create 1 DUMMY [JFA] for (Owner of u_FacelessHunter) at TempLoc facing Default building facing degrees
          • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
          • Unit - Add Hunting Shade // dummy to (Last created unit)
          • Unit - Set level of Hunting Shade // dummy for (Last created unit) to (Level of Hunting Shade // for u_FacelessHunter)
          • Unit - Order (Last created unit) to Night Elf Druid Of The Talon - Faerie Fire (Picked unit)
      • Custom script: call RemoveLocation(udg_TempLoc)
Ok i know this one. We can manually set and remove location with this method.
Set TempLoc = (Position of u_FacelessHunter)
Custom script: call RemoveLocation(udg_TempLoc)

But is it doing as people said?

Custom script: set bj_wantDestroyGroup = true
Unit Group - Pick every unit in (Units within 750.00 of bla bla bla

It will destroy this group after usage? Is it correct? Should i not put this after the Unit Group?
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
4,992
What you are doing is correct usage of bj_wantDestroyGroup.

It is important to know what it does. There are a various few functions (in JASS, what GUI is behind the scenes) that check the value of bj_wantDestroyGroup when they are run. When you set that boolean variable (true/false variable) you tell the map the next time a function is called that checks that bj_wantDestroyGroup variable, it should immediately destroy the group after the function is done doing whatever it does.

So the idea is that you set that boolean whenever you want the group to be automatically cleaned up in the line that you put right after the line where you set the boolean. The most important function that does this is ForGroupBJ which is "Pick every unit in <Group> and do <Actions>", but there are others like GroupPickRandomUnit ("Random Unit from <Group>"). You can see how they look below:
JASS:
    function ForGroupBJ takes group whichGroup, code callback returns nothing
        // If the user wants the group destroyed, remember that fact and clear
        // the flag, in case it is used again in the callback.
        local boolean wantDestroy = bj_wantDestroyGroup
        set bj_wantDestroyGroup = false
   
        call ForGroup(whichGroup, callback)
   
        // If the user wants the group destroyed, do so now.
        if (wantDestroy) then
            call DestroyGroup(whichGroup)
        endif
    endfunction

    function GroupPickRandomUnit takes group whichGroup returns unit
        // If the user wants the group destroyed, remember that fact and clear
        // the flag, in case it is used again in the callback.
        local boolean wantDestroy = bj_wantDestroyGroup
        set bj_wantDestroyGroup = false
   
        set bj_groupRandomConsidered = 0
        set bj_groupRandomCurrentPick = null
        call ForGroup(whichGroup, function GroupPickRandomUnitEnum)
   
        // If the user wants the group destroyed, do so now.
        if (wantDestroy) then
            call DestroyGroup(whichGroup)
        endif
        return bj_groupRandomCurrentPick
    endfunction
Most group leaks can be cleaned this way, but is not something you always want to do. If the group you are working with does not need to be destroyed yet but you still want to pick every unit in the group and do something, you don't have to clean the leak yet so you don't set the boolean variable. It is important never to set this boolean except immediately before you are ready to destroy the group for this reason:

Triggers that trigger other triggers interrupt themselves. That may seem complicated to translate but it makes sense in English. What it means is that if Trigger A runs when any unit dies, and Trigger B kills Unit C and then Unit D... when B is run, C will be killed, then A will run once, then D will be killed, then A will run again.

It is possible that if you set this boolean variable too early, and then something in your trigger that comes before the line that would normally create and then immediately destroy a group (the "Unit group - pick" line) triggers another trigger... the flag being set will cause a different group to be destroyed unexpectedly when its units are Picked in that triggered trigger!
 
Level 21
Joined
Mar 29, 2020
Messages
1,237
also, you created the variable "temploc" but then you went and created and leaked another point at that same location when you referred to the location of the unit and not to the variable you created in the line:

Unit Group - Pick every unit in (Units within 750.00 of (Position of u_FacelessHunter) matching...

you should just use temploc there. that's the whole point of creating the variable.
 
Status
Not open for further replies.
Top