I’ll preface this by saying I know how to beat the level from reading other posts, but I’d still like to know what’s wrong with my initial code attempt.
I start by sorting the different enemy types into arrays so I can prioritize them later.
var enemies = this.findEnemies();
var archers = [];
var soldiers = [];
var scouts = [];
var shamans = [];
var ogres = [];
var evilAnya = [];
for (var i = 0; i < enemies.length; i++){
var enemy = enemies[i];
if (enemy.type === "archer"){
archers.push(enemy);
}
if (enemy.type === "soldier"){
soldiers.push(enemy);
}
Ect. Then my plan was to go Archers > Shamans > Ect, by doing the following:
if(archers){
for(var a = 0; a < archers.length; a++){
var target = archers[a];
if (target){
this.attack(target);
}
}
}
else if(shamans){
for(var s = 0; s < shamans.length; s++){
var target2 = shamans[s];
if (target2){
this.attack(target2);
}
}
}
This works fine to kill all the archers, but then it gets stuck and won’t break out of my first for loop. What am I doing wrong?