I’ve looked at other people’s questions and solutions but I can’t figure out why mine isn’t working. The problem is that as soon as my hero summons a second Griffin Rider, it flies to the edge of the minefield and then just hovers over it and doesn’t start moving and attacking until the first one is dead. I can’t figure out what is making it stop.
// The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
function chooseStrategy() {
var enemies = hero.findEnemies();
var enemy = hero.findNearest(enemies);
// If you can summon a griffin-rider, return "griffin-rider"
if (hero.gold >= hero.costOf("griffin-rider")) {
return "griffin-rider";
}
// If there is a fangrider on your side of the mines, return "fight-back"
else if (enemy && enemy.pos.x < 35 && enemy.type == "fangrider") {
return "fight-back";
}
// Otherwise, return "collect-coins"
else {
return "collect-coins";
}
}
function commandAttack() {
// hero.say("command Attack");
// Command your griffin riders to attack ogres.
var friends = hero.findFriends();
for (var i = 0; i < friends.length; i++) {
var friend = friends[i];
var enemy = friend.findNearest(friend.findEnemies());
if (enemy && enemy.type != "fangrider" ) {
hero.command(friend, "attack", enemy);
}
}
}
function pickUpCoin() {
// Collect coins
var item = hero.findNearestItem();
if (item) {
hero.moveXY(item.pos.x, item.pos.y);
}
}
function heroAttack() {
// Your hero should attack fang riders that cross the minefield.
var enemy = hero.findNearestEnemy();
if (enemy && enemy.type == "fangrider") {
while (enemy.health > 0) {
hero.attack(enemy);
}
}
}
while(true) {
commandAttack();
var strategy = chooseStrategy();
// Call a function, depending on what the current strategy is.
if (strategy == "collect-coins") {
pickUpCoin();
} else if (strategy == "griffin-rider") {
hero.summon("griffin-rider");
} else if (strategy == "fight-back") {
heroAttack();
}
}
(Additionally, how do I log out from the forums? It seems separate from the main website/game and I am on a shared computer.)