HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Unit not being removed from group

01-30-2010, 11:20 AM#1
Cheezeman
Cheers.
Keeping it short I'm making a spell in which I want to make 6 random units invisible. For this I'm removing the unit from my group when I've made it invisible (using GroupRemoveUnit() ).
However, my debugmessages say that he's being retargeted.

(msgs)
1048726
1048723
1048710
1048710
1048710
1048710

Collapse Part of interest:
        loop
            call ForGroup( g, function GroupPickRandomUnitEnum )
            exitwhen i > NumberOfEffected( level ) or bj_groupRandomCurrentPick == null
            
                call BJDebugMsg( I2S( GetHandleId( bj_groupRandomCurrentPick ) ) )
                call SaveUnitHandle( hash, GetHandleId( g ), i, bj_groupRandomCurrentPick )
                call UnitAddAbilityEx( bj_groupRandomCurrentPick, PERMANENT_INVIS_ID )
                call SetUnitPathingEx( bj_groupRandomCurrentPick, false )
                call GroupRemoveUnit( g, bj_groupRandomCurrentPick )
                call GroupRemoveUnit( g, bj_groupRandomCurrentPick )
                
            set i = i + 1            
        endloop
Expand GroupPickRandomUnitEnum:
Expand Entire Code:

Any idea of what's going on?
01-30-2010, 01:27 PM#2
Michael Peppers
Collapse GroupPickRandomUnitEnum:
function GroupPickRandomUnitEnum takes nothing returns nothing
    set bj_groupRandomConsidered = bj_groupRandomConsidered + 1
    if (GetRandomInt(1,bj_groupRandomConsidered) == 1) then
        set bj_groupRandomCurrentPick = GetEnumUnit()
    endif
endfunction

I bet that's why it happens. bj_groupRandomCurrentPick doesn't change unless that integer thing is always 1, that's why a unit gets retargeted. I guess *even* this:

Collapse GroupPickRandomUnitEnum:
function GroupPickRandomUnitEnum takes nothing returns nothing
set bj_groupRandomCurrentPick = GetEnumUnit()
endfunction

would be more effective for your purpose, since the already targeted units would be out of the group.

Also:
Collapse JASS:
        loop
            call ForGroup( g, function GroupPickRandomUnitEnum )
            exitwhen i > NumberOfEffected( level ) or bj_groupRandomCurrentPick == null
            
                call BJDebugMsg( I2S( GetHandleId( bj_groupRandomCurrentPick ) ) )
                call SaveUnitHandle( hash, GetHandleId( g ), i, bj_groupRandomCurrentPick )
                call UnitAddAbilityEx( bj_groupRandomCurrentPick, PERMANENT_INVIS_ID )
                call SetUnitPathingEx( bj_groupRandomCurrentPick, false )
                call GroupRemoveUnit( g, bj_groupRandomCurrentPick )
                call GroupRemoveUnit( g, bj_groupRandomCurrentPick )
                
            set i = i + 1            
        endloop
Duplicate.
01-30-2010, 02:58 PM#3
Cheezeman
GroupPickRandomUnitEnum is made by blizzard and I highly doubt it's disfunctional...
And that duplicate is unneccessary, was just a test to see if it for some reason would work.

I had a version before which used GetEnumUnit() but it kept targeting the same units in a specific pattern, so I decided to rewrite it. It didn't look very natural.
01-30-2010, 03:03 PM#4
Michael Peppers
Quote:
Originally Posted by Cheezeman
GroupPickRandomUnitEnum is made by blizzard and I highly doubt it's disfunctional...
It depends on what you're coding, for giving you a random unit, without changing the group later and admitting the pick of the same random unit again as a possibility, it's fine, but it isn't thought to be working in a situation like yours... you have to code another one.
01-30-2010, 03:16 PM#5
Iron_Doors
I think you're missing something that Blizzard does:
Collapse JASS:
//===========================================================================
// Picks a random unit from a group.
//
function GroupPickRandomUnit takes group whichGroup returns unit
    // 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_groupRandomConsidered = 0
    set bj_groupRandomCurrentPick = null
    call ForGroup(whichGroup, function GroupPickRandomUnitEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(whichGroup)
    endif
    return bj_groupRandomCurrentPick
endfunction
If I were you I would try adding those two lines right before your ForGroup call, and see if it helps.
01-30-2010, 05:26 PM#6
Cheezeman
Thanks a lot Iron_Doors, you saved the day! +rep on that