• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ HD Level Design Contest #1 POLL is now OPEN! Check out the stunning visuals of the final entries. 🔗Click here to cast your vote!

Do dead units eventually get removed from unit groups?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
I think they don't. Dead units can also be added into unit groups.

Okey tried to follow a tutorial about group iterations but it doesn't work..

JASS:
    private function OnTimerEnd takes nothing returns nothing
        local unit u 
        loop
            set u = FirstOfGroup(playerHungryUnits[pNum])
            exitwhen u == null
            call GroupRemoveUnit(playerHungryUnits[pNum], u)
            if UnitAlive(u) then
                call BJDebugMsg("readded")
                call GroupAddUnit(swap, u)
            endif
            if pNum == 0 then
                call BJDebugMsg(GetUnitName(u))
            endif
        endloop
        call BJDebugMsg("--------------")

        set temp = playerHungryUnits[pNum]
        set playerHungryUnits[pNum] = swap
        set swap = temp

        if pNum < 12 then 
            set pNum = pNum + 1 
        else 
            set pNum = 0
        endif
    endfunction

It runs twice for player 0 then there apears to be no more units in the group...
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
even removed unit stay inside groups, there is no way for them to be removed, because the underlying representation of unit has no idea about anything called group, and to automatically remove unit from all groups, the unit would need to know all the groups it is in, and then remove itself proprely from them
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
I never seen a shadow unit, so I can't, maybe because I rarely use FirstOfGroup loops.
 
As edo said, shadow references will stay in the unit group's memory. They won't be enumerated with ForGroup(), but FirstOfGroup() loops will eventually hit them--and the unit handle will return null, causing a premature exit. However, you can use something similar to GroupRefresh (link) to get rid of those references.

You can modify GroupRefresh to remove dead units as well. Dead units aren't considered shadow references--not until the game removes them (e.g. after corpse decay), so you can tweak the refresh to remove them sooner.
 
Status
Not open for further replies.
Top