[SOLVED] Level borrowed-sword does not work

Level borrowed-sword should work, but it does not.
“Goals incomplete” it says
Can somebody take a look at it?

# In diesem Level wird dein Held nicht kämpfen.
# Befehle deinen Schützen auf den Gegner mit der höchsten Gesundheit zu schießen
def opfer(units):
    #enemies = hero.findEnemies()
    enemyIndex = 0
    strongest = None
    besthealth = 0
    for enemyIndex in range(len(units)):
        enemy = units[enemyIndex]
        if enemy.health > besthealth:
            besthealth = enemy.health
            strongest = enemy
        return strongest 

while True:
    enemies = hero.findEnemies()
    friends = hero.findFriends()
    Index = 0
    for Index in range(len(friends)):
        friend = friends[Index]
        target = opfer(enemies)
        if friend.type == "archer" and target:
            hero.command(friend, "attack", target)

Cay you, please check if it works for you?

You need to put the return strongest after the for loop, otherwise it will just return the first enemy in the array.

Oh, thanks! It works!

Pls mark the solution

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