Wednesday, April 18, 2012

removing units in a unit group with jass?

hello, once again I'm having a jass problem. I can't figure out how to make this:


Code:
function Trig_Untitled_Trigger_001_Copy_Copy_Func001002 takes nothing returns nothing
call RemoveUnit( GetEnumUnit() )
endfunction

function Trig_Untitled_Trigger_001_Copy_Copy_Actions takes nothing returns nothing
call ForGroupBJ( udg_initunits[1], function Trig_Untitled_Trigger_001_Copy_Copy_Func001002 )
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001_Copy_Copy takes nothing returns nothing
set gg_trg_Untitled_Trigger_001_Copy_Copy = CreateTrigger( )
call TriggerAddAction( gg_trg_Untitled_Trigger_001_Copy_Copy, function Trig_Untitled_Trigger_001_Copy_Copy_Actions )
endfunction

into one function. I can't translate


Code:
call ForGroupBJ( udg_initunits[1], function Trig_Untitled_Trigger_001_Copy_Copy_Func001002 )

to
Code:
call RemoveUnit( GetEnumUnit() )

note: i want to remove the unit from the game, not from the unit group|||Firstly, RemoveUnit will remove the unit from the game, GroupRemoveUnit removes the unit from the unit group. Secondly, there's a native for what you're trying to accomplish. Try this:


Code:
function Trig_Untitled_Trigger_001_Copy_Copy_Actions takes nothing returns nothing
call GroupClear( udg_initunits[1] )
endfunction
|||Yea, hey. Sry, I mixed this thread up with my other thread, I actually DO want to remove these units from the game, not from the unit group.... xD

What was I thinking when I wrote the topic post? here's the full loop:


Code:
    call GroupAddUnitSimple( gg_unit_n00F_0009, udg_initunits[1] )
call GroupAddUnitSimple( gg_unit_ncop_0005, udg_initunits[1] )
call GroupAddUnitSimple( gg_unit_n00F_0010, udg_initunits[2] )
call GroupAddUnitSimple( gg_unit_ncop_0008, udg_initunits[2] )
call GroupAddUnitSimple( gg_unit_n00F_0011, udg_initunits[3] )
call GroupAddUnitSimple( gg_unit_ncop_0007, udg_initunits[3] )
call GroupAddUnitSimple( gg_unit_n00F_0012, udg_initunits[4] )
call GroupAddUnitSimple( gg_unit_ncop_0006, udg_initunits[4] )
loop
exitwhen i > 4
if ( GetPlayerSlotState(ConvertedPlayer(i)) == PLAYER_SLOT_STATE_PLAYING ) then
call SetPlayerStateBJ( ConvertedPlayer(i), PLAYER_STATE_RESOURCE_GOLD, 50 )
call ForceAddPlayerSimple( ConvertedPlayer(i), udg_playingplayers )
set i = i + 1
else
call RemoveUnit( GetEnumUnit() )
set i = i + 1
endif
endloop
endfunction

this version of the trigger does NOT work. It RUNS, but it doesn't remove the non-playing player's units. Ergo,
Code:
            call RemoveUnit( GetEnumUnit() )

is faulty|||GetEnumUnit() only has meaning when used in conjunction with things like ForGroup. When you want to use ForGroup functionality, you're going to have to go with a seperate function, as you did in your original post.|||okay, so what if I don't want either a separate function, GetEnumUnit(), nor ForGroup then?

How should it look if I want to find units in a unit group and remove the from the game?

1) Pick all units in udg_initunits[i]

2) Remove Picked units.

That's all i want to do :S|||Frankly, using a seperate function and ForGroup is the best way, but if you really want to do it without a seperate function, you can do this:


Code:
local unit u = null
loop
set u = FirstOfGroup(udg_initunits[i])
exitwhen (u == null)
call RemoveUnit(u)
endloop

In that code i has been used to represent the converted player id.|||Ok, I guess you're right. I'm just amazed that it would be so much trouble picking all units in a unit group and removing them from the game in just one function...

No comments:

Post a Comment