"Lurkers" Level gets stuck in infinite loop

# findEnemies returns a list of all your enemies.
# Only attack shamans. Don't attack yaks!

enemies = hero.findEnemies()
enemyIndex = 0

# Wrap this section in a while loop to iterate all enemies.
# While the enemyIndex is less than the length of enemies
while enemyIndex < len(enemies):
    enemy = enemies[enemyIndex]
    if enemy.type == 'shaman':
        while enemy.health > 59:
            hero.attack(enemy)
# Remember to increment enemyIndex
enemyIndex += 1

Recently, my code on this level kept failing because it was “either really slow or is an infinite loop.” I checked out a different forum post on the same topic and their code matched and worked perfectly fine when they ran it.
I’m completely stuck here because it seems theres no reason for it to fail. My hero also just won’t go anywhere for some reason.
I would appreciate help.

enemyIndex += 1 isn’t indented, you need to indent it, right now it’s only looking at one enemy

4 Likes
while enemyIndex < len(enemies):
    enemy = enemies[enemyIndex]
    if enemy.type == 'shaman':
        while enemy.health > 59:
            hero.attack(enemy)
# Remember to increment enemyIndex
    enemyIndex += 1 # <- Indent this inside the loop

That’s what I just said @Watamelon

1 Like

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