Need help with Mountain Mercenaries


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.costOf("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);

I don’t know why but the problem is said to be in the “enemy” in hero.command line. Please help. Thank you.


Do that. (via for loop)

By the way, make sure to read the FAQ before you just dump the code in your post.


My code is restarted ;-;


you added var soldierIndex = 0 inside the loop, which will make the soldierIndex constantly be either 0 or 1. Also, when you move, you shouldn’t specify the position of the coin. You should just move to the coin’s position without specifying the position.