Hello there. I need help with my mountain mercenaries code. There is a problem I do not understand.
Here is my code:
// Gather coins to summon soldiers and have them attack the enemy.
while(true) {
// Move to the nearest coin.
var coin = hero.findNearestItem();
// Use move instead of moveXY so you can command constantly.
hero.move({x: coin.pos.x, y: coin.pos.y});
// If you have funds for a soldier, summon one.
if (hero.gold > hero.costOf("soldier")) {
hero.summon("soldier");
}
while(true) {
var enemy = hero.findNearest(hero.findEnemies());
if (enemy) {
// Loop over all your soldiers and order them to attack.
var soldiers = hero.findFriends();
var soldierIndex = 0;
var soldier = soldiers[soldierIndex];
// Use the 'attack' command to make your soldiers attack.
//hero.command(soldier, "attack", enemy);
hero.command(soldier, "attack", enemy);
soldierIndex+=1;
}
}
}
I don’t know why but the problem is said to be in the “enemy” in hero.command line. Please help. Thank you.