# \[SOLVED\] Help on Lurkers

**URL:** <https://discourse.codecombat.com/t/solved-help-on-lurkers/23087>\
**Category:** Level Help\
**Created:** [July 16, 2020, 8:10pm UTC](https://discourse.codecombat.com/t/solved-help-on-lurkers/23087 "2020-07-16T20:10:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LunaFromTheMoon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lunafromthemoon/32/37747_2.png) [@LunaFromTheMoon](https://discourse.codecombat.com/u/LunaFromTheMoon)\
**Post date:** [July 16, 2020, 8:10pm UTC](https://discourse.codecombat.com/t/solved-help-on-lurkers/23087/1 "2020-07-16T20:10:27Z")

</div>

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:

```python
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

```

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [July 16, 2020, 8:15pm UTC](https://discourse.codecombat.com/t/solved-help-on-lurkers/23087/2 "2020-07-16T20:15:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LunaFromTheMoon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lunafromthemoon/32/37747_2.png) [@LunaFromTheMoon](https://discourse.codecombat.com/u/LunaFromTheMoon)\
**Post date:** [July 16, 2020, 8:18pm UTC](https://discourse.codecombat.com/t/solved-help-on-lurkers/23087/3 "2020-07-16T20:18:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [July 16, 2020, 8:22pm UTC](https://discourse.codecombat.com/t/solved-help-on-lurkers/23087/4 "2020-07-16T20:22:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LunaFromTheMoon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lunafromthemoon/32/37747_2.png) [@LunaFromTheMoon](https://discourse.codecombat.com/u/LunaFromTheMoon)\
**Post date:** [July 16, 2020, 8:25pm UTC](https://discourse.codecombat.com/t/solved-help-on-lurkers/23087/5 "2020-07-16T20:25:43Z")

</div>

Thanks! She now kills them 😃

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [July 17, 2020, 8:25am UTC](https://discourse.codecombat.com/t/solved-help-on-lurkers/23087/6 "2020-07-17T08:25:49Z")

</div>

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