HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[Q]bj_wantDestroyGroup Problem.....

02-04-2004, 06:23 AM#1
danny760311
I last made a trigger with the line:

Unit Group - Pick every unit in (Units of type Cerebrate) and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Picked unit) is alive) Equal to True
Then - Actions
Trigger - Run Spawn Egg <gen> (checking conditions)
Else - Actions

I wanna the group be destroyed after doing the pick. So I added a line:

Custom script: set bj_wantDestroyGroup = true
Unit Group - Pick every unit in (Units of type Cerebrate) and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Picked unit) is alive) Equal to True
Then - Actions
Trigger - Run Spawn Egg <gen> (checking conditions)
Else - Actions

But after that, the pick doesn't work. Why?
02-04-2004, 07:04 AM#2
Alakafizz
i cant give you an explanation as to why it doesnt work, but you could probably get around it another way.

When you do your Pick - then save the picked units to a unit-group variable instead of just running the trigger in the loop - actions. Then in another trigger, count the numbers of units in this unit and run your Spawn Egg trigger this number of times.

I'd be interested in the explanation too, if anyone knows?
02-04-2004, 07:33 AM#3
danny760311
I found the reason, fxxk blizzard:
Code:
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

Code:
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)
        [b]call GroupAddGroup(g, result)[/b]

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

    return result
endfunction

So it only picked all player 1 units as a result.......................0_o

Fxxxy blizzard....:nono:
02-04-2004, 07:50 AM#4
Grater
Mmmmm interesting, I'll have to watch out for that because its the sort of thing that might be hard to catch in single player testing.

Ofcourse the bj_wantDestroyGroup=true is called a hack for a reason.
02-04-2004, 08:43 AM#5
Cubasis
Yes, that's quite a interesting find there,

Now i'll have to be paranoid and check if there are any more surprises in the unit-group functions :/. Although i always tend to manually Destroy the groups instead, and it seems that it (destroying it manually) still works.

Anyways, thanks for pointing this out danny.

Cubasis
02-04-2004, 09:26 AM#6
danny760311
I think, and hope there's no more bug about groups.

BTW, group functions are so many loops0_o

Something confuses me is that why blizzard uses such a loop for checking whether a group is empty:

Code:
function IsUnitGroupEmptyBJEnum takes nothing returns nothing
    set bj_isUnitGroupEmptyResult = false
endfunction

function IsUnitGroupEmptyBJ takes group g returns boolean
    // 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_isUnitGroupEmptyResult = true
    call ForGroup(g, function IsUnitGroupEmptyBJEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(g)
    endif
    return bj_isUnitGroupEmptyResult
endfunction

In my view:

Code:
function IsUnitGroupEmptyBJ takes group g returns boolean
[b]  local boolean result[/b]
    // 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

    [b]set result = ( FirstOfGroup(g) == null )[/b]

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(g)
    endif
[b]    return result[/b]
endfunction

It could reduce the loop, couldn't it?
02-04-2004, 10:11 AM#7
Grater
Thinking about it, seems like a bug. The correct behaivour for GetUnitsOfTypeIdAll would be to preserve the value of bj_wantDestroyGroup using a local and set it to false before using GroupAddGroup.

The "FirstOfGroup" thing also puzzles me a bit, the function would be much simpler without the callback. Ofcourse theres nothing stopping anyone using FirstOfGroup as a subsitute for IsUnitGroupEmptyBJ in custom script.
02-04-2004, 08:32 PM#8
Sage the Mage
Heh I always wondered why Pick Units of Type didnt work with bj_wantDestroyGroup...