# Help on Sarven Shepherd\[SOLVED\]

**URL:** <https://discourse.codecombat.com/t/help-on-sarven-shepherd-solved/28449>\
**Category:** Level Help\
**Created:** [April 17, 2021, 4:37pm UTC](https://discourse.codecombat.com/t/help-on-sarven-shepherd-solved/28449 "2021-04-17T16:37:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![21-Nikkil\_Amarnath](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/21-nikkil_amarnath/32/22016_2.png) [@21-Nikkil\_Amarnath](https://discourse.codecombat.com/u/21-Nikkil_Amarnath)\
**Post date:** [April 17, 2021, 4:37pm UTC](https://discourse.codecombat.com/t/help-on-sarven-shepherd-solved/28449/1 "2021-04-17T16:37:07Z")

</div>

Please help me in this code=The code I typed is not working no matter how much I try.  
Here is the code

```python
while True:
    enemies = hero.findEnemies()
    enemyIndex = 0

    # Wrap this logic in a while loop to attack all enemies.
    # Find the array's length with: len(enemies)
while enemyIndex < len(enemies):
    enemy = enemies[enemyIndex]
    # "!=" means "not equal to."
if enemy.type != "sand-yak":
        # While the enemy's health is greater than 0, attack it!
    while enemy.health > 0:
            hero.attack(enemy)
    pass

```

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [April 17, 2021, 5:14pm UTC](https://discourse.codecombat.com/t/help-on-sarven-shepherd-solved/28449/2 "2021-04-17T17:14:35Z")

</div>

You have to increment (increase by one) enemyIndex inside the while enemyIndex \< len(enemies): loop.  
You should add enemyIndex += 1 to increase enemyIndex. At the moment, enemyIndex will stay at 0 and you’ll get an infinite loop.  
Make sure you put enemyIndex += 1 inside the second while loop, but outside the if enemy.type != “sand-yak”: statement.  
Danny

---

<div class="post-metadata">

**Author:** ![21-Nikkil\_Amarnath](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/21-nikkil_amarnath/32/22016_2.png) [@21-Nikkil\_Amarnath](https://discourse.codecombat.com/u/21-Nikkil_Amarnath)\
**Post date:** [April 19, 2021, 6:49am UTC](https://discourse.codecombat.com/t/help-on-sarven-shepherd-solved/28449/3 "2021-04-19T06:49:49Z")

</div>

Your advice was good but I did the level with 2 lines of code.`while True:

```
hero.buildXY("fire-trap", 36, 30)
hero.buildXY("fire-trap", 59, 31)

```

`

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [April 19, 2021, 9:28am UTC](https://discourse.codecombat.com/t/help-on-sarven-shepherd-solved/28449/4 "2021-04-19T09:28:00Z")

</div>

> [@21-Nikkil\_Amarnath](#):
>
> but I did the level with 2 lines of code.`while True:

So, you learnt to plant bombs and didn’t learn incrementin?))

---

<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:** [April 19, 2021, 9:28pm UTC](https://discourse.codecombat.com/t/help-on-sarven-shepherd-solved/28449/5 "2021-04-19T21:28:21Z")

</div>

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