# Sarven Road moving problem

**URL:** <https://discourse.codecombat.com/t/sarven-road-moving-problem/6649>\
**Category:** Uncategorized\
**Created:** [February 1, 2016, 12:01pm UTC](https://discourse.codecombat.com/t/sarven-road-moving-problem/6649 "2016-02-01T12:01:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FinnTheWhovian](https://avatars.discourse-cdn.com/v4/letter/f/958977/32.png) [@FinnTheWhovian](https://discourse.codecombat.com/u/FinnTheWhovian)\
**Post date:** [February 1, 2016, 12:01pm UTC](https://discourse.codecombat.com/t/sarven-road-moving-problem/6649/1 "2016-02-01T12:01:28Z")

</div>

So I’ve been trying to complete the Sarven Road level for a few days now and nothing seems to be working. Here’s my code:

* * *

```
enemies = self.findEnemies()
x = self.pos.x
y = self.pos.y
for enemy in enemies:
    loop:
        if enemy:
            self.attack(enemy)
        else:
            self.moveXY(x + 10, y + 10)
        pass

```

* * *

The problem is my hero isn’t moving. Weirdly, I’ve tried some other stages but he still doesn’t move.

Thanks - Finn

---

<div class="post-metadata">

**Author:** ![Hinkle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hinkle/32/3967_2.png) [@Hinkle](https://discourse.codecombat.com/u/Hinkle)\
**Post date:** [February 1, 2016, 1:07pm UTC](https://discourse.codecombat.com/t/sarven-road-moving-problem/6649/2 "2016-02-01T13:07:31Z")

</div>

Right…  
You shouldn’t be using a for loop at this point. To find an enemy you should:

```python
enemies = self.findEnemies()
self.findNearest(enemies)

```

The problem is that you are going through all the enemies and if they are not an enemy you will move.  
Everything in enemies is an enemy, so you will never move.

Delete `for enemy in enemies:`

---

<div class="post-metadata">

**Author:** ![AdrianCgw](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AdrianCgw](https://discourse.codecombat.com/u/AdrianCgw)\
**Post date:** [February 1, 2016, 3:24pm UTC](https://discourse.codecombat.com/t/sarven-road-moving-problem/6649/3 "2016-02-01T15:24:47Z")

</div>

Better start from scratch, the world updates will still be outside the loop.  
Basically you code should be like:

```python
loop:
    update world view - find enemies, own position, items, etc.
    #react to the info you just got
    if (enemy)
          attack enemy
    else
          move

```

---

<div class="post-metadata">

**Author:** ![Joe\_Butcher](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/joe_butcher/32/3691_2.png) [@Joe\_Butcher](https://discourse.codecombat.com/u/Joe_Butcher)\
**Post date:** [February 2, 2016, 5:31pm UTC](https://discourse.codecombat.com/t/sarven-road-moving-problem/6649/4 "2016-02-02T17:31:04Z")

</div>

Your not defining `enemy` You need to use the `self.findNearest()` command and define enemies in the `()`  
Example:

```python
enemies = self.findEnemies()
enemy = self.findNearest(enemies)

```

---

<div class="post-metadata">

**Author:** ![FinnTheWhovian](https://avatars.discourse-cdn.com/v4/letter/f/958977/32.png) [@FinnTheWhovian](https://discourse.codecombat.com/u/FinnTheWhovian)\
**Post date:** [February 4, 2016, 2:33pm UTC](https://discourse.codecombat.com/t/sarven-road-moving-problem/6649/5 "2016-02-04T14:33:08Z")

</div>

All finished now, thanks for everyone’s help!
