• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

set bj_wantDestroyGroup = true, not working (resolved)

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,893
Edit:

This trigger wasn't working for units belonging to anyone besides Player 1:
  • Actions
    • Custom script: set bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in (Units of type Footman) and do (Actions)
      • Loop - Actions
        • Unit - Kill (Picked unit)
I was under the impression that it would clean up the Unit Group leak without any issues.

But as Icemanbo has informed me, it's actually working as intended (see his post below).
 
Last edited:
Code
JASS:
boolexpr           filterGetUnitsOfTypeIdAll         = null
 ...
filterGetUnitsOfTypeIdAll = Filter(function GetUnitsOfTypeIdAllFilter)

function GetUnitsOfTypeIdAll takes integer unitid returns group
    local group   result = CreateGroup()
    local group   g      = CreateGroup()
    local integer index

    set index = 0
    loop
        set bj_groupEnumTypeId = unitid
        call GroupClear(g)
        call GroupEnumUnitsOfPlayer(g, Player(index), filterGetUnitsOfTypeIdAll)
        call GroupAddGroup(g, result)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
    call DestroyGroup(g)

    return result
endfunction

function GroupAddGroup takes group sourceGroup, group destGroup 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

    set bj_groupAddGroupDest = destGroup
    call ForGroup(sourceGroup, function GroupAddGroupEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(sourceGroup)
    endif
endfunction
function GetUnitsOfTypeIdAll is the function being called. It loops over all players and always sets group "g" to all units of respective unit type for one player.
Also, it will always add all units from group "g", the units by the player, to overall result group "result", doing so for each player, using function GroupAddGroup.

So function GroupAddGroup is being called for each player. Inside, it checks for boolean bj_wandDestroyGroup, and will destroy the group "g" from before.
As result, no further player units can't be added no more, as "g" group is destroyed.

In short, PickAllUnitsOfType isn't compatible to use bj_wantDestroyGroup by design. Custom group variable should be used with call DestroyGroup().
 
Status
Not open for further replies.
Top