Page 1 of 1
Killed unit
Posted: Mon Sep 24, 2012 3:28 pm
by enric
Is there a function to call to know which unit has been killed?
I want to have a call, in the tick function, and be able to take several steps when unit has been killed.
Re: Killed unit
Posted: Mon Sep 24, 2012 3:43 pm
by pipfromslitherine
You could grab the unit ID in to a global at the start of the mission - if you know where the unit starts - then just check in Tick whether it is dead. You can also use a KILL_CALLBACK function, but looking at the code, currently it only uses the first one it finds, which isn't ideal. I will add allowing >1 KILL_CALLBACK to the task list.
Cheers
Pip
Re: Killed unit
Posted: Tue Sep 25, 2012 7:16 am
by enric
I found I (more o less solution), but I've another question now related to the scripting language: which is the best way to implement a Select Case?.
As no ELSEIF, or Switch, or Select Case exists, now I use:
if a == 0
{
doanything
}
if a == 3
{
doanything
}
if (a == 6) || (a ==9)
{
doanything
}
etc., but this is a tedious task and dirty code when you have more than then cases.
Re: Killed unit
Posted: Tue Sep 25, 2012 12:18 pm
by rf900
With the limited subset that it has using multiple ifs is the easiest way to go (and sometimes the only one), you write a lot of lines but at least is understandable.
Try also to see if the doanything stuff inside each could be defined with a function and dependent on a variable/s. That way you may substitute the multiple ifs with a for loop.
Re: Killed unit
Posted: Tue Sep 25, 2012 1:26 pm
by enric
Try also to see if the doanything stuff inside each could be defined with a function and dependent on a variable/s
Yes, this will be a solution on some cases, but as BA only return integers when you need to switch by a string…
Imagine the situation I'm checking every killed unit, to know which kind of unit is I use IsUnitSquadType(id, string) where string is "Artillery" or "infantry", etc.
if (IsUnitSquadType(id, string) == 1)
{
}
one if for each possible case.
if (IsUnitSquadType(id, string) == 1)
{
}
If you've a better idea please tell me how.