# Sarven Shepherd(python)

**URL:** <https://discourse.codecombat.com/t/sarven-shepherd-python/23908>\
**Category:** Level Help\
**Created:** [September 5, 2020, 1:20am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908 "2020-09-05T01:20:35Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [September 5, 2020, 1:20am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/1 "2020-09-05T01:20:35Z")

</div>

my hero never moves. I’ve tried putting the code in, and out of the while true loop. I’ve tried moving the “enemyIndex += 1” around. please help

```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)
            enemyIndex += 1
            pass
        

# Between waves, move back to the center.
hero.moveXY(40, 32)
   

```

---

<div class="post-metadata">

**Author:** ![Grzmot](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/grzmot/32/13514_2.png) [@Grzmot](https://discourse.codecombat.com/u/Grzmot)\
**Post date:** [September 5, 2020, 1:54am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/2 "2020-09-05T01:54:37Z")

</div>

For this level it wants you to pretty much create an over-complicated loop where you want to attack enemies. For this I actually just created a basic loop like this:

```python
while True:
    enemy = hero.findNearestEnemy()
    enemyIndex = 0
    if enemy.type != "sand-yak":
        hero.attack(enemy)

```

You should try this out and see if it works for you.

Grzmot

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [September 5, 2020, 2:50am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/3 "2020-09-05T02:50:36Z")

</div>

Thanks, that was way easier. My whole code:

```python
while True:
    
    enemy = hero.findNearestEnemy()
    if enemy.type != "sand-yak":
        hero.attack(enemy)
        

```

My hero was slow to react to the enemy though.It was wierd. 🤔 🤔

---

<div class="post-metadata">

**Author:** ![Destroyer5023](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/destroyer5023/32/14913_2.png) [@Destroyer5023](https://discourse.codecombat.com/u/Destroyer5023)\
**Post date:** [September 5, 2020, 3:06am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/4 "2020-09-05T03:06:02Z")

</div>

move the hero.moveXY(40, 32) into the while enemyIndex \< len(enemies): loop and add enemyIndex = enemyIndex + 1 below the hero.moveXY

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [September 5, 2020, 3:08am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/5 "2020-09-05T03:08:00Z")

</div>

I just don’t get these loops. I’m already stuck on the next level. 😧 😧 😭

---

<div class="post-metadata">

**Author:** ![Destroyer5023](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/destroyer5023/32/14913_2.png) [@Destroyer5023](https://discourse.codecombat.com/u/Destroyer5023)\
**Post date:** [September 5, 2020, 3:08am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/6 "2020-09-05T03:08:31Z")

</div>

which one is it i can help you

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [September 5, 2020, 3:09am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/7 "2020-09-05T03:09:50Z")

</div>

The level is Shine Getter. Should I make a new topic?

---

<div class="post-metadata">

**Author:** ![Destroyer5023](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/destroyer5023/32/14913_2.png) [@Destroyer5023](https://discourse.codecombat.com/u/Destroyer5023)\
**Post date:** [September 5, 2020, 3:10am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/8 "2020-09-05T03:10:26Z")

</div>

yeah(20characters)…

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [September 5, 2020, 3:10am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/9 "2020-09-05T03:10:51Z")

</div>

Or if you want to just explain the loops, you can send message.

---

<div class="post-metadata">

**Author:** ![Destroyer5023](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/destroyer5023/32/14913_2.png) [@Destroyer5023](https://discourse.codecombat.com/u/Destroyer5023)\
**Post date:** [September 5, 2020, 3:11am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/10 "2020-09-05T03:11:16Z")

</div>

yeah i didn’t know you finished the levels

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [September 5, 2020, 3:12am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/11 "2020-09-05T03:12:21Z")

</div>

huh? what do you mean?

---

<div class="post-metadata">

**Author:** ![Destroyer5023](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/destroyer5023/32/14913_2.png) [@Destroyer5023](https://discourse.codecombat.com/u/Destroyer5023)\
**Post date:** [September 5, 2020, 3:13am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/12 "2020-09-05T03:13:07Z")

</div>

never mind…

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [September 5, 2020, 3:13am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/13 "2020-09-05T03:13:54Z")

</div>

Sooo… I’ll just make new topic.

---

<div class="post-metadata">

**Author:** ![Destroyer5023](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/destroyer5023/32/14913_2.png) [@Destroyer5023](https://discourse.codecombat.com/u/Destroyer5023)\
**Post date:** [September 5, 2020, 3:14am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/14 "2020-09-05T03:14:14Z")

</div>

yup pretty much(20chars)

---

<div class="post-metadata">

**Author:** ![CocoCharlie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cococharlie/32/19081_2.png) [@CocoCharlie](https://discourse.codecombat.com/u/CocoCharlie)\
**Post date:** [September 5, 2020, 3:18am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/15 "2020-09-05T03:18:25Z")

</div>

The link: [Shine Getter(python)](https://discourse.codecombat.com/t/shine-getter-python/23909)

---

<div class="post-metadata">

**Author:** ![Destroyer5023](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/destroyer5023/32/14913_2.png) [@Destroyer5023](https://discourse.codecombat.com/u/Destroyer5023)\
**Post date:** [September 5, 2020, 3:19am UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/16 "2020-09-05T03:19:10Z")

</div>

i know i’m trying to figure out what’s wrong with yr code

---

<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:** [September 5, 2020, 3:19pm UTC](https://discourse.codecombat.com/t/sarven-shepherd-python/23908/17 "2020-09-05T15:19:12Z")

</div>

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