Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Mountain mercenaries debugging help

# 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 
    enemy = hero.findNearestEnemy()
    coin = hero.findNearestItem()
    if coin:
    # If you have funds for a soldier, summon one.
    if > hero.costOf("soldier"):

    if enemy:
        soldiers = hero.findFriends()
        soldierIndex = 0
        soldier = soldiers[soldierIndex]
        # Loop over all your soldiers and order them to attack
        hero.command(soldier, "attack", enemy)

This is my code and it only lets one of the soldiers I summon attack at a time. therefore my hero keeps dying.

Also another complication that may be why my person keeps dying, the paid version is unavailable for me at the moment.

Howdy and welcome to the forum!

In your ‘if block’, you need to iterate through your soldiers array, commanding each of them to attack…one then the other, etc.

Don’t forgot to increment your counter too!

I accidentally beat the level in an unintended way by messing around with the builders hammer. fire traps and fences work better than people.

Well good! Ingenuity is not a bad thing. Even Nick once stated (paraphrased)…“It’s not a bad thing to solve a level, even if it is not by then intended methods. It’s the solving that counts.”

you need

soldierIndex+= 1