Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Sarven Shepherd- I need help


When I try to run Sarven Shepherd, my hero just stands there. Nothing happens, no ogres come, and the computer says, "Fix your code. Code never finished. It’s either really slow or has an infinite loop."
My code is this:

# Use while loops to pick out the ogre

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!
            enemyIndex += 1

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


Its because your incrementing in your if statement. Just take enemyIndex += 1 out of the if statement.