If so, you'll need to use either enumArea(), enumRange() or enumDroid() to get a list of the enemy droids after spawning. As you know where you're spawning them, enumArea() or enumRange() would be an economical choice.
Those enum*() functions return an array of droid objects. Now, they might return some droids you don't want, but there's a way to get round that...
Code: Select all
var spawned = 0;
function toLastSpawn(obj) {
return ( obj.name.indexOf(":" + spawned) != -1 );
}
function spawnDroid(player, x, y, name, body, propulsion, reserved, droidType, turret1, turret2, turret3) {
// turret2 and turret3 are optional
if (arguments.length < 9) throw new Error("spawnDroid(): Invalid parameters!");
var droid = null;
// append name with spawn count
arguments[3] += ":" + spawned;
// spawn droid
if ( addDroid.apply(this, arguments) ) {
// droid was added, return it's droid object
droid = enumArea(x, y, x, y).filter(toLastSpawn);
droid = (droid.length) ? droid[0] : null;
}
// increment spawn counter
++spawned;
return droid;
}
@Per - it would be much more useful if addDroid() returned the DROID object for the newly created droid, or null if there was a problem. I imagine same is true for addStructure() and addFeature() functions.
Remember that Goth can't add a label to the spawned droid until he has it's droid object
If the game object was returned from those functions, my code sample above would be:
Code: Select all
var newDroid = addDroid(...);


