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

[General] Question about bj_wantDestroyGroup=true

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,853
What happened when I do bj_wantDestroyGroup=true?, because I thought that just eliminate the groups created in GUI in the same trigger, but I had this problem:
[General] - I'm tired of this (Workers doing action that they shouldn't do)
And results that I checked that an important group ("Trabajadores") was eliminated at some point so I removed the function "bj_wantDestroyGroup=true" the group wasn't created in the same trigger and results the group didn't get eliminate, so I think "bj_wantDestroyGroup=true" destroy all GUI groups, Am I correct?
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
In short, a unit group is just a single line in GUI but in JASS it becomes more complex.
Remember, the editor will always translate your GUI to JASS upon running/saving the map.

Using a unit group uses the ForGroupBJ function

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

At the bottom, you can see that the group is destroyed if bj_wantDestroyGroup is set to true beforehand.
And at the top bj_wantDestroyGroup is set to false, meaning that it resets itself to false (default value) every time a unit group is used

Once bj_wantDestroyGroup is set to true it destroys the next unit group created.
 
Level 24
Joined
Jun 26, 2020
Messages
1,853
In short, a unit group is just a single line in GUI but in JASS it becomes more complex.
Remember, the editor will always translate your GUI to JASS upon running/saving the map.

Using a unit group uses the ForGroupBJ function

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

At the bottom, you can see that the group is destroyed if bj_wantDestroyGroup is set to true beforehand.
And at the top bj_wantDestroyGroup is set to false, meaning that it resets itself to false (default value) every time a unit group is used

Once bj_wantDestroyGroup is set to true it destroys the next unit group created.
So why this happened?
but I had this problem:
[General] - I'm tired of this (Workers doing action that they shouldn't do)
And results that I checked that an important group ("Trabajadores") was eliminated at some point so I removed the function "bj_wantDestroyGroup=true" the group wasn't created in the same trigger and results the group didn't get eliminate
 
Level 24
Joined
Jun 26, 2020
Messages
1,853
I checked in the trigger is a function that runs another trigger when I am using that eliminated group before a function that creates another group, so bj_wantDestroyGroup=true destroy the next USED group.

Edit: Correction, it only happen if I use "Pick every unit in...", and no matter if the group is a variable.
 
Last edited:
Level 20
Joined
Feb 27, 2019
Messages
593
What happens if you do something like this. Does this create a unit group leak or is it automatically discarded?
  • Set VariableSet Nearby_Target_Kenneth = (Random unit from (Units within 3200.00 of Loc[7] matching (((Unit-type of (Matching unit)) Equal to Scared Pig) and ((((Matching unit) is alive) Equal to True) and ((((Matching unit) is invulnerable) Equal to False)
 
Level 20
Joined
Feb 27, 2019
Messages
593
Why would it be automatically destroyed in your example? You can use variable + call destroy(), or use bj_wantDestroyGroup.
Working in your case with bj_wantDestroyGroup would be fine. "(Random unit from)" would destroy the created group "(Units within... )", if bj_wantDestroyGroup is true.
Because it doesnt use the exact function pick every unit, or perheaps it does and is just hidden in gui. I dont know how it works. Also setting Loc = Position of unit doesnt create a leak at position of unit if Loc is removed, it is however a bit different ofcourse. Thanks for the reply.
 
Status
Not open for further replies.
Top