Re: MogulAI
Posted: 13 Nov 2010 16:10
Hmm, yea now I see Selling an aircraft causes a DoCommand which is not allowed in a Valuator call. So your loop is still needed, but you can use a foreach loop whenever you don't need the extra power of a regular loop.
Note that the ", _" is absolutely needed in order for the foreach to work as wanted. The underscore is a second looping variable that will contain the AIList values. If only one looping variable is provided, it will contain the values, not the keys.
An alternative in case you're desire is to minimize the amount of code:
Code: Select all
function AIAI::DeleteVehiclesInDepots()
{
local list = AIVehicleList();
list.Valuate(AIVehicle.IsStoppedInDepot);
list.KeepValue(1);
foreach(q, _ in list)
{
AIVehicle.SellVehicle(q);
}
return list.Count();
}
An alternative in case you're desire is to minimize the amount of code:
Code: Select all
function AIAI::DeleteVehiclesInDepots()
{
local list = AIVehicleList();
foreach(q, _ in list)
{
AIVehicle.IsStoppedInDepot(q) && AIVehicle.SellVehicle(q);
}
return list.Count();
}