HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

set bj_wantDestroyGroup = true ?

08-17-2009, 02:21 AM#1
Fluff
I don't understand this line of code exactly:

Collapse JASS:
set bj_wantDestroyGroup = true

Can someone explain what it does and when to use it and when not to use it?

I added it in front of some of my GUI triggers because I understood (perhaps incorrectly) that it is supposed to clean up leaks in a trigger like this:

Trigger:
Farm Income
Collapse Events
Time - IncomeTimer expires
Conditions
Collapse Actions
Custom script: set bj_wantDestroyGroup = true
Collapse Unit Group - Pick every unit in (Units of type Farm) and do (Actions)
Collapse Loop - Actions
Player - Add 40 to (Owner of (Picked unit)) Current gold
Player - Add 20 to (Owner of (Picked unit)) Current lumber
08-17-2009, 02:32 AM#2
TotallyAwesome
It sets a global variable to "true". The function below, that picks units, uses this variable to identify if it should destroy the group after the actions are done, or not. Just put it
Collapse JASS:
set bj_wantDestroyGroup = true
always there, and you won't leak groups.
08-17-2009, 02:59 AM#3
Fluff
Ok, that's what I thought, I guess. Is it okay to use it in a GUI trigger like I posted? I ask because as far as I can tell, that trigger only works for the first Farm unit and then stops.
08-17-2009, 03:54 AM#4
Pyrogasm
It should work fine in a situation like that; that's what it's designed to be used for.
08-17-2009, 05:21 AM#5
Fluff
That trigger seems to only work for units owned by Player 1, which is weird. I don't know why that is.
08-17-2009, 09:17 AM#6
0zyx0
That's because
Trigger:
Unit Group - Pick every unit in (Units of type Farm) and do (Actions)
First creates a group called g and puts every Farm owned by player 1 in it, and then adds all units in that group to another group. If bj_wantDestroyGroup is true, it destroys the group g the first time the content of one group is added to another group.
08-17-2009, 09:48 AM#7
Maxus
Here's what it does if you look inside:
Collapse 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

So if you set bj_wantDestroyGroups = true, unit group which units are picked from is destroyed at the end of this script, which prevents from leaking and this global variable is set to false again.

But the same problem you have happened to me when I was picking unit of type. I think maybe it destroys the group before using more than one players. I used this while having only Player 7 units of this type and nothing happened (he may have started with Player 1).

I suggest that using classical way for destroying groups is better, this helped me solve the problem:
You must have a Unit Group variable type like "TempGroup" declared in globals:
Trigger:
Farm Income
Collapse Events
Time - IncomeTimer expires
Conditions
Collapse Actions
Set TempGroup = (Units of type Farm)
Collapse Unit Group - Pick every unit in TempGroup and do (Actions)
Collapse Loop - Actions
Player - Add 40 to (Owner of (Picked unit)) Current gold
Player - Add 20 to (Owner of (Picked unit)) Current lumber
Custom script: call DestroyGroup(udg_TempGroup)
08-17-2009, 11:37 AM#8
Anitarf
Expand The problem isn't in ForGroupBJ, it's in GetUnitsOfTypeIdAll:
Expand Or, more precisely, another function it calls:

And this is why GUI sucks.