I have a problem with my code: whenever I run it, it ignores the function that commands my friends but not the one that commands my hero.
// You can find friends through walls, but not enemies(unless you have twighlight glasses! Only 500 gems in the item shop).
// Watch out for smooth, frictionless ice patches!
function friendAttack() {
var friends = hero.findFriends();
for (var i = 0; i < friends.length; i++) {
var friend = friends[i];
var ogres = friend.findNearest(hero.findByType("ogre"));
var witches = friend.findNearest(hero.findByType("witch"));
var enemy = friend.findNearestEnemy();
var ogre = hero.findByType("ogre");
if (enemy) {
if (friend.type == "paladin") {
if (friend.health <= 450 && friend.canCast("heal")){
hero.command(friend, "cast", "heal", friend);
} else if (witches){
hero.command(friend, "attack", witches);
}else{
hero.command(friend, "attack", enemy);
}
} else if (friend.type == "archer") {
if (witches) {
hero.command(friend, "attack", friend.findNearest(hero.findByType("witch")));
} else {
hero.command(friend, "attack", enemy);
}
} else if (ogres) {
hero.command(friend, "attack", ogres);
} else {
hero.command(friend, "attack", enemy);
}
} else {
hero.command(friend, "move", {
x: 50,
y: 57
});
hero.command(friend, "move", {
x: 50,
y: 39
});
hero.command(friend, "move", {
x: 78,
y: 40
});
}
}
}
function AttackOrMove() {
var enemy = hero.findNearestEnemy();
if (enemy) {
if (hero.canCast("chain-lightning")) {
hero.cast("chain-lightning", enemy);
} else if (hero.isReady("bash")) {
hero.bash(enemy);
hero.shield();
} else {
hero.attack(enemy);
}
} else {
hero.moveXY(78, 14);
}
}
hero.moveXY(70, 15);
while (true) {
AttackOrMove();
friendAttack();
}