why can the self.distanceTo(enemy) not work in this level !?
it works for me… post some code.
Thats because self.findEnemies returns an array of enemies. You need to get a single enemy and pass it into distanceTo
loop: if self.distanceTo(self.findNearest(self.findEnemies())) < 10: pass else: pass
should work. but i dont know python so just a guess
I keep getting a really stupid error that says find distance to target unit
not stupid likely there’s no enemy around at the time. try breaking it apart and using an if enemy
loop: enemy = self.findNearest(self.findEnemies()) if enemy: if self.distanceTo(enemy) < 10: pass else: pass
This is the lesson that was supposedly learned in Patrol Buster. In general, if you are struggling with something in a level, go back and look at earlier levels for keys to the code.
I think I had that issue in one of the desert levels. It just kept complaining about distance like crazy on specific line.
that is my problem to
Having the same issue ever since I unlocked the desert world.
loop: nearest_yaks = self.findNearest(self.findEnemies()) for yak in nearest_yaks: if self.distanceTo(yak) < 10: # Error: Find the distance to a target unit. x = self.pos.x + 10 y = self.pos.y self.moveXY(x, y)
While trying to debug, I printed
self.say(yak) and it outputs the string “distance”. So either
yak is a string in my case or it’s an object (like I expect it to be) and has a method like
__str__ overridden to return “distance”, but that doesn’t make much sense.
It’s because you are passing findEnemies through findNearest findNearest returns only the nearest single enemy. Your code looks like it’s expecting the results from findEnemies which returns all the enemies.
You’re very right! Another pair of eyes definitely helps when you have tunnel vision, thanks.