# Basin Stampede Help

What is wrong with my code?

loop:
enemy = self.findNearest(self.findEnemies())
if enemy and self.distanceTo(enemy) < 10:

``````     x = self.pos.x
y = self.pos.y - 10
self.moveXY(x, y)
else:
pass
x = self.pos.x
y = self.pos.y + 10
self.moveXY(x, y)
``````

It looks like youâ€™re using the wrong code to try and solve this level.

In Basin Stampede you want to check whether the Yaks are above or below you, and move accordingly. Not move up if they are close, down if they are far.

You may also consider increasing your X valueâ€¦

whats wrong with this code?

# 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.
hero.pos.y - 3
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
hero.pos.y + 3
pass
hero.moveXY(xPos, yPos)
``````

The problem is in these lines:

Youâ€™ve changed your pos, not yPos.
Hope this helps!

that was a great hint but the code doesnâ€™t work still this is my code.

``````# 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 - 3
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
yPos + 3
pass
hero.moveXY(xPos, yPos)
``````

the problem of the code is in the running corner it only lights up the hero.move(xpos, ypos)

Try this, instead of just using the `if enemy:` conditional, try putting `if enemy and hero.distanceTo(enemy) < 12:`. That way, when the yaks get closer than the given distance, it triggers the while True loop to iterate through the if conditional at a specific event. Also, the code isnâ€™t using the reassigned values of yPos in the conditional statements. However, if you change `yPos - 3` and `yPos + 3` to `hero.moveXY(xPos, yPos - 3)` and `hero.moveXY(xPos, yPos + 3)` respectively, the hero then moves properly.

You may have to adjust the numbers a little bit (I did) but with these changes you should see the correct movement of the hero.

Or you could just say: yPos -= 3 and yPos += 3 and that reassigns the variable yPos, thatâ€™s what i used and itâ€™s really simple.

Thanks for the amazing help guys I got the level finished
well because I got rocked to the oasisâ€¦

Hi! I donâ€™t understand whatâ€™s wrong with my code. I looked the hints over and over. Please help.

``````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.
enemy.pos.y > hero.pos.y
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
enemy.pos.y < hero.pos.y
pass
hero.moveXY(xPos, yPos)

``````

I tried the same thing, however, it didnâ€™t work.

I actually figured it out.
For anyone who needs help, here are some hints and pointers.

``````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.
hero.pos.y = #subtract 3 from the hero.pos.y
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
hero.pos.y = #add 3 to hero.pos.y
pass
hero.moveXY(xPos, yPos)
``````
1 Like

@Rachel699 please do not revive dead topics unless you have problems at the same level. I see that you needed help, and that you solved your problem, so just try to remember that for the future.

Andrei

Oh. Ok. I just joined yesterday, thanks!

1 Like

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

I ned heeelp this is my code: 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.
hero.pos.y = #subtract 3 from the hero.pos.y
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
hero.pos.y = #add 3 to hero.pos.y
pass
hero.moveXY(xPos, yPos)

Hi, please learn to format your code properly using the </> at the top.

Hi @Aaron5137 and welcome to the forum!

Can you format your code as it is described here so we will be able to help you?

Andrei

It should be on the right of the quotes and the left of the heart.