[Solved] Hunter Valley Help!


#1

This is my code:
def moveDownRight(step):
hero.moveXY(hero.pos.x + step, hero.pos.y - step)

The function has the hero move to up and right.

def moveUpRight(step):
# Complete this function:
hero.moveXY(hero.pos.x + step, hero.pos.y - step)
pass

The hunter is kind and will show the route.

hunter = hero.findFriends()[0]
route = hunter.route
routeIndex = 0

while routeIndex < len(route):
direction = route[routeIndex]
if direction > 0:
moveUpRight(8)
else:
# Use a function moveDownRight with the shift 8:
moveDownRight(8)
pass
routeIndex += 1
But for some reason, my hero just moves into the traps


#2

Please learn to post your code properly. It just requires a very small amount of effort.

To post your code from the game, use the </> button or it won’t format properly. When you click the </> button, the following will appear:

Please paste ALL of your code inside the triple back tick marks.

``` <— Triple back tick marks.

Paste ALL of your code in here.

``` <— Triple back tick marks.

There are many people here willing and able to help. If you use the </> button correctly, then ALL of your code should look like this:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    else:
        hero.say("My code is formatted properly")

If ALL of your code isn’t formatted like the code above, then you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well.

Thank you.


#3
def moveDownRight(step):
    hero.moveXY(hero.pos.x + step, hero.pos.y - step)

# The function has the hero move to up and right.
def moveUpRight(step):
    # Complete this function:
    hero.moveXY(hero.pos.x - step, hero.pos.y + step)
    pass

# The hunter is kind and will show the route.
hunter = hero.findFriends()[0]
route = hunter.route
routeIndex = 0

while routeIndex < len(route):
    direction = route[routeIndex]
    if direction > 0:
        moveUpRight(8)
    else:
        # Use a function moveDownRight with the shift 8:
        moveDownRight(8)
        pass
    routeIndex += 1`Preformatted text`

#4

This is my code properly formatted


#5

In the second function (the one you wrote), moveUpRight(step), think about the direction you will move according to hero’s position minus the step. No wonder your guy is confused. :rofl:


#6

What do you mean by that


#7

Which direction is X minus step?


#8

I don’t know? I just reversed the old function


#9

Now answer my question for the win. The second function is not just the inverse of the first.


#10

So then what is the function supposed to be


#11

If you are at an X coordinate and subtract a number from it and then move to that X coordinate, in what direction are you moving? Compare that answer to the name of your function and then look at the code you’ve written.

Seriously, I can’t be more specific than that without just giving you the answer.