Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Lurkers level help

Hello, I am new to these forums, so sorry if this is a duplicate…
I need help on the Lurkers level in the desert biome.
My hero just stands there doing nothing, and after a while, the ducky appears with the error
“Code never finished. It’s either really slow or it has an infinite loop.”
Here is my code:

# 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)
        enemyIndex += 1
# Remember to increment enemyIndex

Thanks if you can help! :slight_smile:

Hi mightybrayan,

Welcome to the forum!

Decrease the indent on this line:

At the moment if the enemy type isn’t shaman, then…nothing else runs in the code, so the next loop doesn’t happen.

Jenny

You have to delete an indent here.
Lydia

Thanks everyone! :slight_smile: It works now!

Can you check the tick mark next to someone’s comment that helped you the most? Thanks in advance.
Lydia

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