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

[SOLVED] Mountain Mercenairies

My hero summons the soldiers but the soldiers don’t attack.

# 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.
    item = hero.findNearestItem()
    hero.move(item.pos)
    
    
    # If you have funds for a soldier, summon one.
    if hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")
        enemy = hero.findNearest(hero.findEnemies())
    if enemy:
        soldiers = hero.findFriends()
        soldierIndex = 0
        soldier = soldiers[soldierIndex]
        # Loop over all your soldiers and order them to attack.
        while soldier < len(soldiers):
            # Use the 'attack' command to make your soldiers attack.
            #hero.command(soldier, "attack", enemy)
            hero.command(soldier, "attack", enemy)
        soldierIndex += 1

Delete an indent in this line.

In this, you do not need this

Delete that.

This needs to be indented.

You also need to add

soldier = soldiers[soldierIndex]

Right after

Lydia

It worked, thanks Lydia

1 Like

Glad it did!
Lydia
20 chars

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