# Build a "fence" above or below when you see a yak.
x = hero.pos.x
y = hero.pos.y
while True:
yak = hero.findNearestEnemy()
if yak:
# If yak.pos.y is greater than hero.pos.y
if yak.pos.x > hero.pos.y:
# buildXY a "fence" 10m below the yak.
hero.buildXY("fence",yak.pos.x,yak.pos.y - 10)
# else:
else:
# buildXY a "fence" 10m above the yak.
hero.buildXY("fence",yak.pos.x,yak.pos.y + 10)
pass
else:
# moveXY right 10m towards the oasis.
hero.moveXY(x, y)
pass
x += 10
I think it’s because you have said if the yak.pos.x is greater than hero.pos.y, then build a fence below the yak. Shouldn’t the yak.pos.x be yak.pos.y if you are comparing it to hero.pos.y
@Lydia_Song is correct with her adjustment on your hero.move(x,y), you need to give proper coordinates since you didn’t define the x and y variables.
And good catch by @abc on the x vs y coordinate correction. Typos and calling the wrong variables will sneak in an wreak havoc on your code every time and they can be difficult to spot.