OASIS distance problems


#1

why can the self.distanceTo(enemy) not work in this level !?


#2

it works for me… post some code.


#3

loop:
if self.distanceTo(self.findEnemies)<10:
pass

else:
    pass

#4

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


#5

I keep getting a really stupid error that says find distance to target unit
(using python)


#6

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

#7

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.


#8

I think I had that issue in one of the desert levels. It just kept complaining about distance like crazy on specific line.


#9

that is my problem to


#10

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 yak with 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.


#11

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.


#12

You’re very right! Another pair of eyes definitely helps when you have tunnel vision, thanks.