What did I do wrong? when i clicked on test level nothing happened.
function defendLane(event) {
// Remember to create a variable for the target, to remember:
var unit = event.target;
// Save the unit’s starting pos.x
var startX = unit.pos.x;
while(true) {
var enemy = unit.findNearestEnemy();
// If there is an enemy, use unit.attack to attack!
if (Enemy)
unit.attack(Enemy);
Else;
unit.moveXY(startX, 16); // ∆
}
}
game.spawnXY(“soldier”, 9, 16);
game.spawnXY(“soldier”, 30, 16);
game.spawnXY(“soldier”, 54, 16);
game.spawnXY(“soldier”, 75, 16);
game.setActionFor(“soldiers”, “spawn”, defendLane);
With the code below, only one of the soldier move the other 3 stay still.
function defendLane(event) {
// Remember to create a variable for the target, to remember:
var unit = event.target;
// Save the unit’s starting pos.x
var startX = unit.pos.x;
while(true) {
var enemy = unit.findNearestEnemy();
// If there is an enemy, use unit.attack to attack!
if (enemy)
unit.attack(enemy);
Else;
unit.moveXY(startX, 16); // ∆
}
}
game.spawnXY(“soldier”, 9, 16);
game.spawnXY(“soldier”, 30, 16);
game.spawnXY(“soldier”, 54, 16);
game.spawnXY(“soldier”, 75, 16);
game.setActionFor(“soldier”, “spawn”, defendLane);