Bug with findNearest(target) or i miss something


#1

Hey there.
I’ve bought enhanced lenses but can not use findNearest method
Here is a gif to show you the problem - link to my DropBox

Python code is below:

 enemies = self.findEnemies()
 self.say(enemies) # Works fine, return array with 10 enemy names
 i = 0
 while i < len(enemies):
     enemy = self.findNearest(enemies)
     self.say(enemy) # Does not work. Return "Object object" instead of enemy name
     i += 1

The question: is this a bug or I do something wrong?


#2

There’s no bug there. enemy is the enemy object, not the name of the enemy. If you want the name you should be able to access the id property. enemy.id or strangely enough i’ve found this works too.

String(enemy)

The biggest question to me is why you are getting an array of enemy names when saying enemies. That is an array of the enemy objects, not just their names. Perhaps there’s some sort of toString method going on when you say that specific object hidden behind the scenes.

On another note, good luck with my level :slight_smile: it’s a doosy


#3

Ok, thanks for reply.
But I still dont get, why my code does not work. I want to kill 10 nearest enemies, And when I try this:

 enemies = self.findEnemies()
 while i < len(enemies):
     enemy = self.findNearest(enemies)
     self.attack(enemy)
     i += 1
 self.say("done")

I get 2 enemies down and part with say “done”. But I want to kill all enemies in my array.
And here is a gif


#4

In your current code. enemies is static. since you declare it before your loop. It won’t update with the latest coords of the enemies, etc.

move it into your while loop and you might have better luck. Is this your whole code or just a snippet?


#5

That’s all my code at this moment. I’m just trying to understand some parts of programming. Its looks so simply, but I still have problems with it :frowning:
And I think its not possible with my current amount of HP. I have 495 right now. But I’ll do my best :smiley:
Thanks for answer again.


#6

I think I see the problem, let me try translating your code into “English”:

while i < len(enemies):
     enemy = self.findNearest(enemies)
     self.attack(enemy)
     i += 1

While i is less than the number of enemies
Find the nearest enemy in the collection of enemies
Attack that enemy once
Increment i by one.

I believe you would need to be getting one hit kills for this to work the way you intend.


#7

jklauser, you are right. I do not use while enemy.health > 0, cause I have 1 hit kill.


#8

I’m not sure you will be able to get away with that on this level. only for munchkins. shamans throwers etc will take more than one hit even with the great sword. but that aside. does this work a little better for you?

enemies = self.findEnemies()
while i < len(enemies):
  enemy = self.findNearest(enemies)
  self.attack(enemy)
  i += 1
  enemies = self.findEnemies()
self.say("done")

#10

sotonin, your answer really helped me and that part of code works fine.
I have not seen the boss yet, but I’ve done second oasis. So half is done I hope :smiley:


#11

yep. 3 trials then the main boss!