# What is the difference between find enemies

**URL:** <https://discourse.codecombat.com/t/what-is-the-difference-between-find-enemies/3350>\
**Category:** Uncategorized\
**Created:** [April 2, 2015, 6:35pm UTC](https://discourse.codecombat.com/t/what-is-the-difference-between-find-enemies/3350 "2015-04-02T18:35:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArarisValerian](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@ArarisValerian](https://discourse.codecombat.com/u/ArarisValerian)\
**Post date:** [April 2, 2015, 6:35pm UTC](https://discourse.codecombat.com/t/what-is-the-difference-between-find-enemies/3350/1 "2015-04-02T18:35:16Z")

</div>

enemy = self.findNearest(self.findEnemies())  
and  
enemy = self.findNearest(enemies)

I have upgraded my glasses. I know that with the second one I can say, “I’m not attacking you” and I won’t attack. However, with the first one I can say, “I’m not attacking you,” but I will still attack the enemy.  
I literally have the same code in “The Dunes” but with the new glasses it doesn’t work. Obviously, I know how to get it to work, but why doesn’t the first one work?

---

<div class="post-metadata">

**Author:** ![FuzzicalLogic](https://avatars.discourse-cdn.com/v4/letter/f/73ab20/32.png) [@FuzzicalLogic](https://discourse.codecombat.com/u/FuzzicalLogic)\
**Post date:** [April 2, 2015, 8:59pm UTC](https://discourse.codecombat.com/t/what-is-the-difference-between-find-enemies/3350/2 "2015-04-02T20:59:09Z")

</div>

> [@ArarisValerian](#):
>
> enemy = self.findNearest(self.findEnemies())  
> and  
> enemy = self.findNearest(enemies)

Did you mean these? They are both findNearest(). If in fact you meant findNearestEnemy, please adjust your post so I can answer your intention correctly. Both are valid questions with very different answers.

---

<div class="post-metadata">

**Author:** ![FuzzicalLogic](https://avatars.discourse-cdn.com/v4/letter/f/73ab20/32.png) [@FuzzicalLogic](https://discourse.codecombat.com/u/FuzzicalLogic)\
**Post date:** [April 2, 2015, 9:09pm UTC](https://discourse.codecombat.com/t/what-is-the-difference-between-find-enemies/3350/3 "2015-04-02T21:09:14Z")

</div>

##Assuming the original post is as intended

`self.findNearest()` looks at an array of objects or positions and determines which is the closest to the `self` (in this case, the hero). The difference between the two statements is small but significant.

- `self.findNearest(self.findEnemies())` automatically gets the list of enemies as an Array and passes it directly to `findNearest()` so it can choose. This means that there is no processing of the enemies, so they aren’t counted, prioritized, categorized, or … well anything.

- `self.findNearest(enemies)` passes an array variable named `enemies` to `findNearest()`. This array might have been stored from `findEnemies()` or could have been manually created. One use of this is to get the list and remove one type of enemy from the list, so that we could get other data. While this is added capability, often, you’ll simply see the following:

```python
var enemies = self.findEnemies();
var enemy = self.findNearest(enemies);

```

---

<div class="post-metadata">

**Author:** ![FuzzicalLogic](https://avatars.discourse-cdn.com/v4/letter/f/73ab20/32.png) [@FuzzicalLogic](https://discourse.codecombat.com/u/FuzzicalLogic)\
**Post date:** [April 2, 2015, 9:12pm UTC](https://discourse.codecombat.com/t/what-is-the-difference-between-find-enemies/3350/4 "2015-04-02T21:12:40Z")

</div>

##Assuming that OP meant findNearest() and findNearestEnemy()

`self.findNearest()` requires an array of objects or positions. You must have manually gotten them via another `find` function.

`self.findNearestEnemy()` automatically skips the step of getting the enemies for you. Unfortunately, it does not allow for any distinguishing of enemy characteristics. Basically, this is great if you don’t have to avoid sand-yaks or yetis. This is equivalent to `self.findNearest(self.findEnemies())` but is one less instruction.

---

<div class="post-metadata">

**Author:** ![ArarisValerian](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@ArarisValerian](https://discourse.codecombat.com/u/ArarisValerian)\
**Post date:** [April 2, 2015, 9:57pm UTC](https://discourse.codecombat.com/t/what-is-the-difference-between-find-enemies/3350/5 "2015-04-02T21:57:53Z")

</div>

Thank you Fuzzical.🙂

That helped tremendously. In addition, thanks for being very patient and struggling through my ignorance. 😄

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [April 3, 2015, 10:30pm UTC](https://discourse.codecombat.com/t/what-is-the-difference-between-find-enemies/3350/6 "2015-04-03T22:30:40Z")

</div>

The first one will find the nearest current enemies around you

The second one will find the nearest enemies in the array `enemies`
