Help with Sarven Shepherd (Python)!


#1

I have been stuck on the Sarven Shepherd level for about a week and I don’t understand why my code isn’t working! Below is what I have:

while True:
    enemies = hero.findEnemies()
    enemyIndex = 0

    # Wrap this logic in a while loop to attack all enemies.
    # Find the array's length with:  len(enemies)

while enemyIndex < len(enemies):
    enemy = enemies[enemyIndex]
    # "!=" means "not equal to."
    if enemy.type != "sand-yak":
        # While the enemy's health is greater than 0, attack it!
        while enemy.health > 0:
            hero.attack(enemy)
    enemyIndex += 1
    pass

# Between waves, move back to the center.
    hero.moveXY(40, 32)

I have tried several variations of this code, changing the indent level in front of “enemyIndex += 1” and wrapping the entire second while loop within the while True loop, but my character never moves or does anything. If anyone has any advice I would really appreciate it!


#2

Does your code show any errors? Double-check your equipment to make sure the abilities you use in your code can be accessed (for example - I’m not saying this is the case - you may be trying to attack an enemy with a hammer equipped, which produces an error).
Also I think the while-loop should be in the while-true loop, but so far this is not about the code. It could be a bug. This is just a check procedure :slight_smile:


#3

Your first while loop contains only the first two lines.
The second while loop will never be reached, as the first while loop goes on forever.

You need to
Indent all lines beginning with the second while statement