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?
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.
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:
var enemies = self.findEnemies();
var enemy = self.findNearest(enemies);
##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.