hi,
I made this code for the first part of the level, but the hero & friends don’t move and let the enemy attack them.
can you please help me find my mistake? Thanks!
function findEnemy(){
var oof = ["fangriders","throwers","ogres","scouts","munchkins"];
for(var e =0;e<oof.length;e++){
var currentEnemy = oof[e];
if (currentEnemy.length > 0) {
return currentEnemy;
}
else {continue;}
}
}
function unitsAttack(){
var friends = hero.findFriends();
for(var u =0; u<friends.length;u++){
var unit = friends[u];
var toAttack = unit.findNearest(findEnemy());
if (toAttack) {
hero.command(unit, "attack", toAttack);
}
}
}
while(true) {
unitsAttack();
var toAttack = hero.findNearest(findEnemy());
if (toAttack) {
hero.attack(toAttack);
}
}