Mountain mercenaries hero.say

Hi everyone, I don’t understand my code for this level

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

This was my original code but my soldiers were not attacking enemies and my hero was stuck.
I deleted hero.say("I need coins!") and hero.say("I should summon something here!") and it worked but I don’t understand why.
I thought the say function shouldn’t affect other functions.

the say function takes 1 second to compleate so it slows down your code

1 Like

It would slow down the speed that you command your soldiers and your attacking do to delay by the hero.say method

1 Like

And also, once you understand it, mark sulotion, and delete that code

1 Like

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