HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How?

07-23-2008, 07:29 AM#1
TheDamien
Collapse JASS:
local unit u
call BJDebugMsg("Begin")
if (not IsUnitGroupEmptyBJ(G2)) then
    call BJDebugMsg("Debug #1")
endif
set u = FirstOfGroup(G2)
if (u == null) then
    if (not IsUnitGroupEmptyBJ(G2)) then
        call BJDebugMsg("Debug #2")
    endif
    // Other stuff
endif

Can anyone explain how the sequence:
Begin
Debug #1
Debug #2
is possible?

Have I completely misunderstood FirstOfGroup?
07-23-2008, 07:36 AM#2
Vestras
Quote:
Originally Posted by TheDamien
Collapse JASS:
local unit u
call BJDebugMsg("Begin")
if (not IsUnitGroupEmptyBJ(G2)) then
    call BJDebugMsg("Debug #1")
endif
set u = FirstOfGroup(G2)
if (u == null) then
    if (not IsUnitGroupEmptyBJ(G2)) then
        call BJDebugMsg("Debug #2")
    endif
    // Other stuff
endif

Can anyone explain how the sequence:
Begin
Debug #1
Debug #2
is possible?

Have I completely misunderstood FirstOfGroup?

Now, that seems very wierd. Are you sure that was how it was?
07-23-2008, 07:39 AM#3
TheDamien
I am sure. The code was copied directly from the map and those are the only Debug messages.
07-23-2008, 08:56 AM#4
Pyrogasm
I haven't the faintest clue, but perhaps this would help you figure it out.
07-23-2008, 09:13 AM#5
TheDamien
The units are being removed by expiration timers. I can't think why ForGroup would loop over units that FirstOfGroup does not return.
07-24-2008, 01:54 AM#6
TheDamien
Sorry for the premature bump.

This is the minimum amount of code I can reproduce the bug with:

Collapse JASS:
library Bug initializer Init
    globals
        private group G1 = CreateGroup()
        private group G2 = CreateGroup()
        private integer cI = 0
    endglobals
    
    private function Enum takes nothing returns nothing
        set cI = cI+1
    endfunction
    
    private function Test takes nothing returns nothing
        local unit u = CreateUnit(Player(0), 'hwt3', GetRandomReal(-10000., 10000.), GetRandomReal(-10000., 10000.), 0)
        call UnitApplyTimedLife(u, 'BTLF', 0.8)
        call GroupAddUnit(G1, u)
        
        set u = FirstOfGroup(G2)
        if (u == null) then
            set cI = 0
            call ForGroup(G2, function Enum)
            if (cI > 0) then
                call DisplayTimedTextToPlayer(GetLocalPlayer(),0.,0.,60.,I2S(cI))
            endif
            call DestroyGroup(G2)
            set G2 = G1
            set G1 = CreateGroup()
        else
            call GroupAddUnit(G1, u)
            call GroupRemoveUnit(G2, u)
            set u = null
        endif
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterTimerEvent(t, 0.14, true)
        call TriggerAddAction(t, function Test)
    endfunction
endlibrary
07-24-2008, 02:50 AM#7
Vexorian
This reminds me of a problem I had with groups and disease clouds, I thought that the problem was with disease cloud, but it could as well be that the problem happens in general with expiration timers, and this is mainly the reason I do not use ForGroup after waits... (Or ever)