Basin Stampede Help

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.

yPos += 3
or
yPos -= 3

would suffice.

3 Likes

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

2 Likes

picky, picky! :stuck_out_tongue_winking_eye: tks :grin:

3 Likes

No problem! :grinning:

1 Like

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

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

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

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

1 Like

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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I just properly formatted it so that it is easier to read C:

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