Can't finish any levels in desert

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

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

Or in two steps :

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

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

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

forgot to clarify, i have the infinity lenses

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

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

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

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

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:

python doesnt use this. change this to self.


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 = ....

1 Like

now it works :smiley: