Page 1 of 1

GetUnitCount(0)

Posted: Thu Aug 01, 2013 2:10 pm
by enric
I was trying to define a border to exit units and I remembered in Rommel expansion you get a similar rutine.
I tried that rutine, but there should be something wrong with the loop that checks units as the result is that all units with higer id are also removed:

- if you move the unit ID 0 to the border all units are removed (no matter where they are)
- if you move unit 1 to the border all units except unit id 0 are removed
- if you move unit 6 to the border al units with ID >= 6 are removed.
- etc

The rutine is Rescue() and taked from AXIS10.BSF, is called from Tick()

FUNCTION RescueUnits()
{
int id ;
int i ;

for(i=0;i<GetUnitCount(0);i++)
{
id = GetUnitID(0, i) ;

if( GetUnitActive( id ) == 1)
{
if( GetUnitY(id) == 16 ) // 16 is the border
{
// rescue it
// SetGlobal("Rescued", GetGlobal("Rescued")+1) ;

// anything loaded on it?
if( GetLoadedUnit(id) != -1 )
{
// SetGlobal("Rescued", GetGlobal("Rescued")+1) ;
RemoveUnit( GetLoadedUnit(id), 1 ) ;
}

RemoveUnit(id, 1) ;
}
}
}
}

Re: GetUnitCount(0)

Posted: Thu Aug 01, 2013 4:17 pm
by pipfromslitherine
It seems to work correctly in the mission, are you saying you actually see this behaviour occurring? You could well SKIP removing units (because we are deleting units and the positions in the GetUnitID list would change) but I can't see how it would remove additional units.

Cheers

Pip

Re: GetUnitCount(0)

Posted: Thu Aug 01, 2013 4:45 pm
by enric
are you saying you actually see this behaviour occurring?
Yes ( in my scenario test)
You could well SKIP removing units (because we are deleting units and the positions in the GetUnitID list would change) but I can't see how it would remove additional units.
I do not understand well this paragraph.

Don't worry, anyway I managed to get the task using another approach.