I don’t know what’s problem with my code, but every time I run it, my character always build two fences when he passing by the second yak, then got himself stucked…
What should I do to make it right?
I’m sorry if my expression has any problem. English is not my native language but I’m learning it
Here is my code:
loop:
yak = self.findNearestEnemy()
if yak:
# If the yak is above you, build a fence 10m below it.
if yak.pos.y > self.pos.y:
self.buildXY("fence", yak.pos.x, yak.pos.y)
# If the yak is below you, build a fence 10m above it.
if yak.pos.y < self.pos.y:
self.buildXY("fence", yak.pos.x, yak.pos.y + 10)
pass
else:
# Move right 10m towards the oasis.
self.moveXY(self.pos.x + 10, self.pos.y)
pass