HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Interesting?

05-07-2008, 08:32 PM#1
Vexorian
Collapse JASS:
library makecast initializer init
    private function init takes nothing returns nothing
     local unit u=CreateUnit(Player(0),XE_DUMMY_UNITID,0,0,0)
     local group g=CreateGroup()
        call TriggerSleepAction(3.0)
        call GroupAddUnit(g,u)
        if(IsUnitInGroup(u,g)) then
            call BJDebugMsg("yay")
        else
            call BJDebugMsg("nay")
        endif
        call RemoveUnit(u)
        if(IsUnitInGroup(u,g)) then
            call BJDebugMsg("yay")
        else
            call BJDebugMsg("nay")
        endif

        set u=CreateUnit(Player(0),XE_DUMMY_UNITID,0,0,0)
        if(IsUnitInGroup(u,g)) then
            call BJDebugMsg("yay")
        else
            call BJDebugMsg("nay")
        endif

    endfunction

endlibrary
result is:
yay
yay
nay

Collapse JASS:
library makecast initializer init
    private function init takes nothing returns nothing
     local unit u=CreateUnit(Player(0),XE_DUMMY_UNITID,0,0,0)
     local group g=CreateGroup()
        call TriggerSleepAction(3.0)
        call GroupAddUnit(g,u)
        if(IsUnitInGroup(u,g)) then
            call BJDebugMsg("yay")
        else
            call BJDebugMsg("nay")
        endif
        set u=null
        call RemoveUnit(u)
        if(IsUnitInGroup(u,g)) then
            call BJDebugMsg("yay")
        else
            call BJDebugMsg("nay")
        endif
    endfunction

endlibrary
Result is
yay
nay

So, it looks like RemoveUnit does not trigger a loop removal, but the handle destructor does.

Collapse JASS:
library makecast initializer init
    private function Show takes nothing returns nothing
        call BJDebugMsg(GetUnitName(GetEnumUnit()))
    endfunction

    private function init takes nothing returns nothing
     local unit u=CreateUnit(Player(0),XE_DUMMY_UNITID,0,0,0)
     local group g=CreateGroup()
        call TriggerSleepAction(3.0)
        call GroupAddUnit(g,u)
        if(IsUnitInGroup(u,g)) then
            call BJDebugMsg("yay")
        else
            call BJDebugMsg("nay")
        endif
        call RemoveUnit(u)
        call ForGroup(g,function Show)
        if(IsUnitInGroup(u,g)) then
            call BJDebugMsg("yay")
        else
            call BJDebugMsg("nay")
        endif
    endfunction

endlibrary
This one is a jewel, it actually displays the unit's name...

yay
unit name
yay

Anyways, just to confirm:
Collapse JASS:
library makecast initializer init
    private function Show takes nothing returns nothing
        call BJDebugMsg(GetUnitName(GetEnumUnit()))
    endfunction

    private function init takes nothing returns nothing
     local unit u=CreateUnit(Player(0),XE_DUMMY_UNITID,0,0,0)
     local group g=CreateGroup()
        call TriggerSleepAction(3.0)
        call GroupAddUnit(g,u)
        if(IsUnitInGroup(u,g)) then
            call BJDebugMsg("yay")
        else
            call BJDebugMsg("nay")
        endif
        //set u=null
        call RemoveUnit(u)
        if(FirstOfGroup(g)==u) then
            call BJDebugMsg("holy...!")
        else
            call BJDebugMsg("darn!")
        endif
    endfunction

endlibrary

The result:
yay
holy!

Conclusion I wouldn't mess with FirstOfGroup or ForGroup in groups whose contents have stayed there for enough time to allow a unit removal, it is just not worth it, IsUnitInGroup (which btw is the ultimate boolean attachment method for units) though seems to be fine.
05-07-2008, 09:07 PM#2
Dg!Mortal
nice
05-07-2008, 09:45 PM#3
Strilanc
I noticed part of this awhile ago when trying to loop over a temp group using FirstOfGroup. I removed a unit, and all of a sudden the loop didn't work.

The reason? FirstOfGroup was returning a removed unit, and RemoveUnitFromGroup doesn't do anything if you pass a removed unit. So it would get the unit, try to remove it (fail), then repeat. (note: I was actually trying to FIND removed units in the group, which made GroupEnumUnit unusable)
05-08-2008, 06:28 AM#4
zen87
vex if u do SetUnitExplode followed by KillUnit will it be the same?
05-08-2008, 10:33 AM#6
Troll-Brain
Quote:
Originally Posted by Vexorian
So, it looks like RemoveUnit does not trigger a loop removal, but the handle destructor does.

Collapse JASS:
library makecast initializer init

globals
    constant integer XE_DUMMY_UNITID = 'hpea'
endglobals
    
    private function init takes nothing returns nothing
     local unit u=CreateUnit(Player(0),XE_DUMMY_UNITID,0,0,0)
     local group g=CreateGroup()
        call TriggerSleepAction(3.0)
        call GroupAddUnit(g,u)
        if(IsUnitInGroup(u,g)) then
            call BJDebugMsg("yay")
        else
            call BJDebugMsg("nay")
        endif
        call RemoveUnit(u)
        if(IsUnitInGroup(u,g)) then
            call BJDebugMsg("yay")
        else
            call BJDebugMsg("nay")
        endif
        
    //call TriggerSleepAction(0)  
    call BJDebugMsg(I2S(CountUnitsInGroup(g)))

    endfunction

endlibrary

if you uncomment the wait you can see that the unit is removed of the group as well

i've not the skills to explain this but for me Removeunit take some time.
Because after a RemoveUnit you can still get his x/y and so one, but not after a wait.
the engine must do some operations before completly remove it.
For example i think he remove the abilities.
05-08-2008, 11:44 AM#7
Toadcop
and i thought you bid some Bolivian Cocaine =)))

// yes groups are messed. but in fact it's kind a user fault. imo

Quote:
if you uncomment the wait you can see that the unit is removed of the group as well

1. end of current thread action queue
2. 1 frame.

i think it's the first... you can proof it via call TimerStart(CreateTimer(),0,false,function somecallback)
and do the same.
05-08-2008, 12:26 PM#8
Troll-Brain
Quote:
Originally Posted by Toadcop
and i thought you bid some Bolivian Cocaine =)))

// yes groups are messed. but in fact it's kind a user fault. imo



1. end of current thread action queue
2. 1 frame.

i think it's the first... you can proof it via call TimerStart(CreateTimer(),0,false,function somecallback)
and do the same.

never hard drugs, just soft ones.

that should be that but the unit is still removed of the group if you remove the unit.

and explain that :

Collapse JASS:
library Test
    
    function Test takes nothing returns nothing

        call BJDebugMsg("run")
        
        // uncomment only one of this three lines and see the result
        call UnitRemoveAbility(U,'Adef') // the unit receive the order "undefend" two times
        //call KillUnit(U) // the unit receive the ordre undefend one time when she dead and one time more at the end of decay
        //call RemoveUnit(U) // the unit receive the order "undefend" two times
        call BJDebugMsg("end")
    endfunction

endlibrary

Collapse JASS:
scope DisplayOrder initializer Init

    globals
        unit U
    endglobals

    private function Actions takes nothing returns nothing
        call BJDebugMsg(OrderId2String(GetIssuedOrderId()))
    endfunction
    
    private function Init takes nothing returns nothing
    local trigger t =CreateTrigger()
    
    set U=CreateUnit(Player(0),'hfoo',0.0,0.0,0.0)
    
        call TriggerRegisterUnitEvent(t,U,EVENT_UNIT_ISSUED_ORDER)
        call TriggerAddAction(t,function Actions)
        call Test()
    endfunction

endscope

@ Strilanc :

IsUnitHidden return true if the unit is removed
05-08-2008, 05:00 PM#9
Strilanc
Quote:
Originally Posted by Troll-Brain
@ Strilanc :

IsUnitHidden return true if the unit is removed

It also returns true if the unit is hidden. The check I use is GetUnitTypeId == 0, which has no false positives.

That wasn't the issue though. The issue was that I couldn't pop removed units from the group.
05-08-2008, 05:07 PM#10
Troll-Brain
Quote:
Originally Posted by Strilanc
It also returns true if the unit is hidden. The check I use is GetUnitTypeId == 0, which has no false positives.

That wasn't the issue though. The issue was that I couldn't pop removed units from the group.
i have tested all the functions in the api unit, so i can say that this is the only way that i know, and yes it sucks
EDIT : oops sorry i missunderstood