Stuck on Oasis Level

Hey guys sorry to bug you but I can’t figure this one out. My code seems to be right but it says I am not defining x. Here is my code.

while True:
    newX = hero.pos.x 
    newY = hero.pos.y
    enemy = hero.findNearestEnemy()
    if enemy and hero.distanceTo(enemy) < 10:
        # Subtract 10 from x to move left.
        hero.moveXY(x - 10, y)
        # Use moveXY to move to the new x, y position.
        hero.moveXY(newX, newY)
        pass
    else:
        # Add 10 to x to move right.
        hero.moveXY(x + 10, y)
        # Use moveXY to move to the new x, y position.
        hero.moveXY(newX, newY)
        pass

Help would be appreciated

Thanks!

1 Like

Do you mean to use newX instead of x? :wink:

1 Like

The same applies for y you are using x and y which aren’t defined try either defining x and y or using newX and newY instead.

1 Like

First add 10 to newX with += to find where you need to move.
Then, you could use something like hero.moveXY(newX, newY).

1 Like