Help I am stuck in Mountain Mercenaries (Python)

while True:
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    coin = hero.findNearestItem()
    hero.move(coin.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 hero.health > 0:
            hero.command(soldier, "attack", enemy)
    soldierIndex += 1

I slightly change the code, but almost done, I can spawn the soldiers now but they won’t attack if my hero is still alive, what should I do…

Keep it the same as this:

but indent soldierIndex += 1 by 8 spaces. I think your code should work then.

yes, that should work, hold on, you got two soldier = soldier[soldierIndex]. Maybe delete the one at the if enemy:

still not working:( what should I do…

I just found a step closer solution but still not working

while True:
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    coin = hero.findNearestItem()
    hero.move(coin.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]
        while soldierIndex < len(soldiers):
            hero.command(soldier, "attack", enemy)
            soldierIndex += 1

please see this how to solve it? keep trying

1 Like

I solved it!!! but thank for all your help! :smiley:

1 Like

Knew you could do it at the end :slight_smile:

1 Like

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