HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

What is the bj_wantDestroyGroup hack?

03-16-2006, 02:36 AM#1
Moss
I have searched hi and low about this hack. But everywhere I see it mentioned it is spoken of as if everybody has always known what it is. Surely at some point it was first discovered and explained somewhere. I want to know what everybody else knows! What is it good for and how is it used?
03-16-2006, 02:39 AM#2
Vexorian
It is not a hack.

It is a global variable.

Blizzard uses it in some of the blizzard.j functions that take group variables.

In those functions, when that variable is true they will automatically destroy the group they took as an argument and set that variable back to false.

Collapse Typical Example:
//===========================================================================
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

03-16-2006, 02:39 AM#3
Chuckle_Brother
Edit: Damn you Vex, beat me to it.
03-16-2006, 03:41 AM#4
Moss
I'm sorry. I still don't really understand. So bj_wantDestroyGroup is something that basically always equal to true or false? I was thinking maybe it could save the hassle of capturing unit groups as a variable and then destroying the group when you are done with it. Am I mistaken?
03-16-2006, 06:06 AM#5
TaintedReality
Yep, it's simply a value that is either true or false.
03-16-2006, 12:54 PM#6
Chuckle_Brother
Boolean yo, if true it destroys the group you popped into the action, like say if you go:

Trigger:
Custom Script: set bj_wantDestroyGroup = true
Collapse Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
Collapse Loop - Actions
Unit - Kill (Picked unit)

When it goes to do this action it will destroy the group created by "Pick every unit".

But a warning, unless I am mistaken if you destroy a global group you MUST use
Trigger:
Set g = (Random 4 units from (Units in (Playable map area)))
because if I remember correctly destroying global groups that have been added to screws them up and causes them never to function properly again.

Edit: What I mean by the last statement is that "Add unit to group" will not work if you destroy the group, I believe you must use the set group = grouptype
03-16-2006, 05:16 PM#7
The_AwaKening
That is correct. I tried setting it to true a while back and it screwed up other triggers in my map.
03-16-2006, 08:06 PM#8
Moss
Hmm, so I could actually say

Trigger:
Custom Script: set bj_wantDestroyGroup = true
Collapse Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
Loop - Actions
Unit - Kill (Picked unit)

instead of

Trigger:
Set g = (Units in (Playable map area))
Collapse Unit Group - Pick every unit in g and do (Actions)
Loop - Actions
Unit - Kill (Picked unit)
Custom Script: call DestroyGroup(udg_g)

?

So I could save a bunch of lines of code if I just set bj_wantDestroyGroup = true at the beginning of the game and specifically set it false around things where I didn't want it to destroy the group? Do I have that all right? Would that screw up things like the Caster System or other systems?
03-16-2006, 08:08 PM#9
Vexorian
IT could save a pair of lines but I actually think that if you can destroy the group manually it is 100% times better to do so, cause the boolean has a couple of unexpected behaviours
03-17-2006, 03:29 PM#10
Chuckle_Brother
For sure, its just easier to use a temporary group, like you would for locations. Then destroy it afterwards with
Collapse JASS:
call DestroyGroup(udg_NAME)

And no you can't just set it true once, because within the bj functions that use it they reset it to false in the case that you don't want it to fire off anymore. Won't screw up the caster system since from what I have seen Vex does it all manually, may take longer the first time but its better than relying on some lame bj functions.