[SOLVED] Desert: Lurkers (Python)

Hi, I need help.
My hero is not even moving.
I have no idea what else to do.

enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies):
    enemy = enemies[enemyIndex]
    if enemy.type == 'shaman':
        while enemy.health > 0:
            hero.attack(enemy)
    enemyIndex += 1

Guys never mind.
The code works when i click submit.

So it’s solved?
(20)

1 Like

Im having issues with this level please help me.

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

enemiIndex+=1

sorry in advance i don’t know how to do it the way so it’s easy to read

This article will help is that: [Essentials] How To Post/Format Your Code Correctly

# 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
enemiIndex+=1

sorry about that.

No worries!

Your enemiIndex+=1 is misspelled (needs a ‘y’) and is outside of the while loop…you need to indent it with 4 spaces.

1 Like

Thanks for the help @dedreous it worked! again thank you.

1 Like

I tried that and it still doesn’t work.

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

Howdy and welcome to the forum! Please post your code properly formatted. This article will help with that:

3 Likes

hi and welcome to the forum! :partying_face: nice profile pic