[SOLVED] Help on Lurkers

First I thought I was stuck, but some other players said the code (solution) worked for them. It said I had created an infinite loop. I went out of the level and back, it wouldn’t load and it said the same thing. This is my code:

return  #Commented out to stop 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 > 0:
            hero.attack(enemy)
# Remember to increment enemyIndex
enemyIndex += 1

You are incrementing enemyIndex outside of the outer while loop…therefore, enemyIndex will always be less that enemy.length.

My hero still doesn’t move. The “infinite loop” notification has dissipated though.

Define the enemy.pos and then have the hero move to it, then attack…don’t forget to wake him up first :wink:

Thanks! She now kills them :smiley: