HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

FirstOfGroup fails after about 10 minutes

08-22-2008, 03:57 AM#1
The__Prophet
Code:
Collapse JASS:
    call BJDebugMsg("order")
    call BJDebugMsg("# " + I2S(CountUnitsInGroup(AttackForce1)))        
    if CountUnitsInGroup(AttackForce1) > 8 then
        set u = FirstOfGroup(AttackForce1)
        call BJDebugMsg("A 1 " + GetUnitName(u))
        loop
            exitwhen u == null
            call BJDebugMsg("A 1.5")    
            set u = FirstOfGroup(AttackForce1)
            call GroupRemoveUnit(AttackForce1, u)
            call IssuePointOrder(u, "attack", x, y)
            call BJDebugMsg("A 2")    
        endloop 
    endif
    set x = GetLocationX(l2)
    set y = GetLocationY(l2)
    call BJDebugMsg("# " + I2S(CountUnitsInGroup(AttackForce2)))         
    if CountUnitsInGroup(AttackForce2) > 8 then
        set u = FirstOfGroup(AttackForce2)
        call BJDebugMsg("U 1 " + GetUnitName(u))            
        loop
            exitwhen u == null
            call BJDebugMsg("U 1.5")            
            set u = FirstOfGroup(AttackForce2)
            call GroupRemoveUnit(AttackForce2, u)
            call IssuePointOrder(u, "attack", x, y)
            call BJDebugMsg("U 2")    
        endloop
    endif  
As you can see I've littered the trigger with debug messages. I've isolated the problem. About ~10 minutes or so into the game, one of either Force A (1) or Force U (2) or both (although never at the same time), FirstOfGroup starts failing. The CountUnitInGroup shows that the group continues to grow, yet the debug messages go from this:

order
#11
A 1 flamethrower
A 1.5
A 2
A 1.5
~~~~

to:

order
#15
A 1
08-22-2008, 04:17 AM#2
Bobo_The_Kodo
Uhmm, maybe there aren't any units in the group when you run it at ~10 minutes from bugs elsewhere?
08-22-2008, 04:23 AM#3
burningice95
It must be a bug somewhere else, FirstOfGroup() doesn't fail after 10 minutes. Maybe you are using handle vars, and that is messing something up?
08-22-2008, 04:24 AM#4
The__Prophet
Quote:
Originally Posted by Bobo_The_Kodo
Uhmm, maybe there aren't any units in the group when you run it at ~10 minutes from bugs elsewhere?

Thats what the debug messages are for. Trust me, there are units in the group when it fails. And in case i didn't clarify, once FirstOfGroup fails for that group, it doesnt work for the group for the rest of the game.
08-22-2008, 04:33 AM#5
Bobo_The_Kodo
The only reason i could think of, is you setting bj_wantDestroyGroup to true somewhere before this is run, causing the group to be destroyed
08-22-2008, 04:53 AM#6
Blubb-Tec
yeah, try a custom CountUnitsInGroup function, I had problems with something similar(UnitgroupBJs destroying my groups), too.
08-22-2008, 05:13 AM#7
The__Prophet
So I think I solved the problem. I guess dead units sometimes stay in a unitgroup. Setting up a Clean up trigger to remove the unit from the group when it died seems to work.
08-22-2008, 07:14 AM#8
Ammorth
There is a resource in the script section that does just this, clean-up groups to prevent FirstOfGroup() issues. I believe its called Clean Group.

I think it has to do something with the fact that removed units (from the game via decay or RemoveUnit()) still exist in the group, but return null since there is no more unit.
08-22-2008, 11:23 AM#9
Anitarf
The function is GroupRefresh.

However, in your loop, you pretty much empty the group, so I imagine that's just a copy of your original group. Since copies are made with GroupAddGroup and that uses an enum which should be immune to decayed units, I'm wondering if that's really your problem. You should show the whole function, not just a part of it.
08-22-2008, 11:59 PM#10
The__Prophet
Quote:
Originally Posted by Anitarf
The function is GroupRefresh.

However, in your loop, you pretty much empty the group, so I imagine that's just a copy of your original group. Since copies are made with GroupAddGroup and that uses an enum which should be immune to decayed units, I'm wondering if that's really your problem. You should show the whole function, not just a part of it.

Collapse JASS:
function IssueOrder takes nothing returns nothing 
    local location l = XYAttack('u003', "a")
    local location l2= XYAttack('h00D', "u")
    local real x = GetLocationX(l)
    local real y = GetLocationY(l)
    local unit u
    call Move_Stopped()      
    if CountUnitsInGroup(AttackForce1) > 8 then
        set u = FirstOfGroup(AttackForce1)
        if u == null then
            call BJDebugMsg("FirstOfGroup Failure!")
        endif
        loop
            exitwhen u == null
            set u = FirstOfGroup(AttackForce1)
            call GroupRemoveUnit(AttackForce1, u)
            call IssuePointOrder(u, "attack", x, y)  
        endloop 
    endif
    set x = GetLocationX(l2)
    set y = GetLocationY(l2)       
    if CountUnitsInGroup(AttackForce2) > 8 then
        set u = FirstOfGroup(AttackForce2)
        if u == null then
            call BJDebugMsg("FirstOfGroup Failure!")
        endif            
        loop
            exitwhen u == null          
            set u = FirstOfGroup(AttackForce2)
            call GroupRemoveUnit(AttackForce2, u)
            call IssuePointOrder(u, "attack", x, y)   
        endloop
    endif         
    call RemoveLocation(l)
    call RemoveLocation(l2)
    set l = null
    set l2= null
    set u = null        
endfunction