# Basin Stampede Help

**URL:** <https://discourse.codecombat.com/t/basin-stampede-help/7177>\
**Category:** Level Help\
**Created:** [April 5, 2016, 6:14pm UTC](https://discourse.codecombat.com/t/basin-stampede-help/7177 "2016-04-05T18:14:31Z")\
**Posts on this page:** 10\
**Page:** 3

<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 6, 2020, 3:43pm UTC](https://discourse.codecombat.com/t/basin-stampede-help/7177/45 "2020-07-06T15:43:57Z")

</div>

Actually, you are calculating off of dynamic (constantly changing) variable. Instead, you should calculate using the static variable you defined at the top of the code.

```python
yPos += 3
or
yPos -= 3

```

would suffice.

---

<div class="post-metadata">

**Author:** ![Anna](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/anna/32/8378_2.png) [@Anna](https://discourse.codecombat.com/u/Anna)\
**Post date:** [July 6, 2020, 3:44pm UTC](https://discourse.codecombat.com/t/basin-stampede-help/7177/46 "2020-07-06T15:44:54Z")

</div>

@dedreous you have a typo (in the lines of code) …

---

<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 6, 2020, 3:46pm UTC](https://discourse.codecombat.com/t/basin-stampede-help/7177/47 "2020-07-06T15:46:19Z")

</div>

picky, picky! 😜 tks 😁

---

<div class="post-metadata">

**Author:** ![Anna](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/anna/32/8378_2.png) [@Anna](https://discourse.codecombat.com/u/Anna)\
**Post date:** [July 6, 2020, 3:47pm UTC](https://discourse.codecombat.com/t/basin-stampede-help/7177/48 "2020-07-06T15:47:13Z")

</div>

No problem! 😀

---

<div class="post-metadata">

**Author:** ![Monkey\_King5](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/monkey_king5/32/21658_2.png) [@Monkey\_King5](https://discourse.codecombat.com/u/Monkey_King5)\
**Post date:** [March 26, 2021, 8:19pm UTC](https://discourse.codecombat.com/t/basin-stampede-help/7177/49 "2021-03-26T20:19:07Z")

</div>

There is this guy who keeps sneaking up behind me. I keep on dying. Any advice?

---

<div class="post-metadata">

**Author:** ![jka2706](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jka2706/32/13636_2.png) [@jka2706](https://discourse.codecombat.com/u/jka2706)\
**Post date:** [March 26, 2021, 8:47pm UTC](https://discourse.codecombat.com/t/basin-stampede-help/7177/50 "2021-03-26T20:47:36Z")

</div>

Hi Monkey\_King5,

Welcome to the forum! Can you post your code (format it by clicking on the \</\> symbol above), and then we can try to help.

Jenny

---

<div class="post-metadata">

**Author:** ![Bobby123](https://avatars.discourse-cdn.com/v4/letter/b/7ba0ec/32.png) [@Bobby123](https://discourse.codecombat.com/u/Bobby123)\
**Post date:** [August 17, 2021, 11:36am UTC](https://discourse.codecombat.com/t/basin-stampede-help/7177/51 "2021-08-17T11:36:03Z")

</div>

# Keep moving right, but adjust up and down as you go.

while True:  
enemy = hero.findNearestEnemy()  
xPos = hero.pos.x + 5  
yPos = 17  
if enemy:  
# Adjust y up or down to get away from yaks.  
if enemy.pos.y \> hero.pos.y:  
# If the Yak is above you, subtract 3 from yPos.  
yPos = hero.pos.y - 3  
pass  
elif enemy.pos.y \< hero.pos.y:  
# If the Yak is below you, add 3 to yPos.  
yPos = hero.pos.y + 3  
pass  
hero.moveXY(xPos, yPos)

This is my code, but my hero always goes up or down continuously getting himself stuck and killed, pls help

---

<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:** [August 21, 2021, 9:12am UTC](https://discourse.codecombat.com/t/basin-stampede-help/7177/52 "2021-08-21T09:12:04Z")

</div>

Hi @Bobby123, welcome to the forum.  
Your code is almost right. Instead of subtracting 3 and adding 3 to yPos, you have subtracted 3 and added 3 to hero.pos.y, which is not the same thing. yPos is always 17, unless there is an enemy above or below you, then it will be 14 or 20, but after you move it resets to 17, whereas hero.pos.y will not reset. So you need to replace hero.pos.y with the yPos variable.  
I hope this solves your issue.  
Danny

---

<div class="post-metadata">

**Author:** ![moonwatcher348](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/moonwatcher348/32/24126_2.png) [@moonwatcher348](https://discourse.codecombat.com/u/moonwatcher348)\
**Post date:** [August 21, 2021, 3:57pm UTC](https://discourse.codecombat.com/t/basin-stampede-help/7177/53 "2021-08-21T15:57:09Z")

</div>

# Keep moving right, but adjust up and down as you go.

```python
while True:
    enemy = hero.findNearestEnemy()
    xPos = hero.pos.x + 5
    yPos = 17
    if enemy:
        # Adjust y up or down to get away from yaks.
        if enemy.pos.y > hero.pos.y:
            # If the Yak is above you, subtract 3 from yPos.
            yPos = hero.pos.y - 3
            pass
        elif enemy.pos.y < hero.pos.y:
            # If the Yak is below you, add 3 to yPos.
            yPos = hero.pos.y + 3
            pass
    hero.moveXY(xPos, yPos)

```

This is my code, but my hero always goes up or down continuously getting himself stuck and killed, pls help  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
I just properly formatted it so that it is easier to read C:

---

<div class="post-metadata">

**Author:** ![moonwatcher348](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/moonwatcher348/32/24126_2.png) [@moonwatcher348](https://discourse.codecombat.com/u/moonwatcher348)\
**Post date:** [August 21, 2021, 4:10pm UTC](https://discourse.codecombat.com/t/basin-stampede-help/7177/54 "2021-08-21T16:10:51Z")

</div>

Your error is that you adjust your y position **anytime** there is a yak around, and not when its just close to you.

[Previous page](https://discourse.codecombat.com/t/basin-stampede-help/7177.md?page=2)
