Can't finish any levels in desert


#1

Whenever I try to do a level in Desert, I always get "Pass an Array of units to findNearest"
any help? I can’t finish any of the levels
I’m not sure if this is a bug or if I just don’t know how to do an array


#2

this.findEnemies() and this.findItems() and this.findFriends() all return an array. what are you trying to find the nearest of?

probably enemies. so

var enemy = this.findNearest(this.findEnemies());

Will get you the nearest enemy


#3

Or in two steps :

var enemies = this.findEnemies();
var enemy = this.findNearest(enemies);

Here, enemies is the array of all the visible enemies.


#4

for some reason they both don’t seem to work…

forgot to clarify, i have the infinity lenses


#5

The proposed codesnippets should work. Maybe post the code handling exactly this so we can review it?


#6

simple code that i tried, still doesn’t work?


#7

looks like you are mixing python and javascript. you need to get rid of the semicolon after the var enemy line


#8

Sorry, I’m using only javascript, so I give my example in this language.


#9

Oh sorry I didn’t clarify before, I’m using python
and @sotonin, i tried to do what you said, I got rid of the semicolon, but it still doesn’t seem to work?

another screnshot:


#10

python doesnt use this. change this to self.

self.findNearest(self.findEnemies())

#11

var is used in JavaScript and a few other languages to declare a new variable. In python variables are declared implicitly so you should write foo = ... instead of var foo = ....


#12

Thanks,
now it works :smiley: