Cloudrip Mountain - Mountain Mercenaries

i don’t know where i’m wrong.))))
some one help me please)

// Gather coins to summon soldiers and have them attack the enemy.

while(true) {
    // Move to the nearest coin.
    // Use move instead of moveXY so you can command constantly.
    let find = hero.findItems();
    let coins = hero.findNearest(find);
    
   if(coins) {
    hero.move(coins.pos);   
   }
    
    
    // If you have funds for a soldier, summon one.
    if (hero.gold > hero.costOf("soldier")) {
        hero.summon("soldier");
    }
    var enemy = hero.findNearest(hero.findEnemies());
    if (enemy) {
        
        var soldiers = hero.findFriends();
        var soldierIndex = 0;
        var soldier = soldiers[soldierIndex];
        // Loop over all your soldiers and order them to attack.
        while(soldierIndex < soldiers.length) {
                hero.command(soldier, "attack", enemy); 
                soldierIndex++;
            }
           
        }
            // Use the 'attack' command to make your soldiers attack.
            //hero.command(soldier, "attack", enemy);
}

remove the // from
//hero.command(soldier, "attack", enemy);

Not tested but

1	        var soldier = soldiers[soldierIndex];
2	        while(soldierIndex < soldiers.length) {
3	                // put line one here and remove line one
4	                hero.command(soldier, "attack", enemy);
5	                soldierIndex++;
6	            }

Just curious: how do you choose to use let or var?

var is for java if thats what yo mean

id need twice to command to soldier to attack enemy?

if I’m not mistaken then var is an obsolete variable. no one uses it nowadays. Thanks for help

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.