# Can't finish any levels in desert

**URL:** <https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337>\
**Category:** Bugs\
**Created:** [January 14, 2015, 3:14am UTC](https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337 "2015-01-14T03:14:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Billy741](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@Billy741](https://discourse.codecombat.com/u/Billy741)\
**Post date:** [January 14, 2015, 3:14am UTC](https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337/1 "2015-01-14T03:14:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sotonin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sotonin/32/24089_2.png) [@sotonin](https://discourse.codecombat.com/u/sotonin)\
**Post date:** [January 14, 2015, 3:23am UTC](https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337/2 "2015-01-14T03:23:29Z")

</div>

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

probably enemies. so

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

```

Will get you the nearest enemy

---

<div class="post-metadata">

**Author:** ![Vettax](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vettax/32/1514_2.png) [@Vettax](https://discourse.codecombat.com/u/Vettax)\
**Post date:** [January 14, 2015, 9:12am UTC](https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337/3 "2015-01-14T09:12:22Z")

</div>

Or in two steps :

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

```

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

---

<div class="post-metadata">

**Author:** ![Billy741](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@Billy741](https://discourse.codecombat.com/u/Billy741)\
**Post date:** [January 15, 2015, 12:32am UTC](https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337/4 "2015-01-15T00:32:40Z")

</div>

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

forgot to clarify, i have the infinity lenses

---

<div class="post-metadata">

**Author:** ![J\_F\_B\_M](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_f_b_m/32/2756_2.png) [@J\_F\_B\_M](https://discourse.codecombat.com/u/J_F_B_M)\
**Post date:** [January 15, 2015, 1:08am UTC](https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337/5 "2015-01-15T01:08:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Billy741](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@Billy741](https://discourse.codecombat.com/u/Billy741)\
**Post date:** [January 16, 2015, 2:03am UTC](https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337/6 "2015-01-16T02:03:42Z")

</div>

![](https://sea2.discourse-cdn.com/flex016/uploads/codecombat/1935/56c53808131982a7.PNG)

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

---

<div class="post-metadata">

**Author:** ![sotonin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sotonin/32/24089_2.png) [@sotonin](https://discourse.codecombat.com/u/sotonin)\
**Post date:** [January 16, 2015, 2:41am UTC](https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337/7 "2015-01-16T02:41:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Vettax](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vettax/32/1514_2.png) [@Vettax](https://discourse.codecombat.com/u/Vettax)\
**Post date:** [January 16, 2015, 9:49am UTC](https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337/8 "2015-01-16T09:49:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Billy741](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@Billy741](https://discourse.codecombat.com/u/Billy741)\
**Post date:** [January 17, 2015, 3:52am UTC](https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337/9 "2015-01-17T03:52:24Z")

</div>

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: ![](https://sea2.discourse-cdn.com/flex016/uploads/codecombat/1949/f281eb40388c6acc.PNG)

---

<div class="post-metadata">

**Author:** ![sotonin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sotonin/32/24089_2.png) [@sotonin](https://discourse.codecombat.com/u/sotonin)\
**Post date:** [January 17, 2015, 4:32am UTC](https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337/10 "2015-01-17T04:32:27Z")

</div>

python doesnt use this. change this to self.

```python
self.findNearest(self.findEnemies())

```

---

<div class="post-metadata">

**Author:** ![Yaur](https://avatars.discourse-cdn.com/v4/letter/y/8baadc/32.png) [@Yaur](https://discourse.codecombat.com/u/Yaur)\
**Post date:** [January 17, 2015, 5:13am UTC](https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337/11 "2015-01-17T05:13:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Billy741](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@Billy741](https://discourse.codecombat.com/u/Billy741)\
**Post date:** [January 23, 2015, 11:16pm UTC](https://discourse.codecombat.com/t/cant-finish-any-levels-in-desert/2337/12 "2015-01-23T23:16:06Z")

</div>

Thanks,  
now it works 😃
