findNearest should be useable for items

FINE TELEPHOTO GLASSES don’t have the findNearestEnemy and findNearestItem methods anymore and instead a findNearest method. Unfortunately that method only works for units and not for items. There doesn’t seem to be a straightforward way to do findNearestItem anymore.

I would propose that findNearest can also be used for items.

findNearest() works for an array of something with a position. It can be used to find the nearest item, enemy, friend, etc. in an array. Maybe it even works for an array of positions.

For example:

# Equivalent of nearest=self.findNearestItem()
items = self.findItems()
nearest = self.findNearest(items)

Just make sure the argument is an array.

Okay now it works. I don’t know what I did wrong the first time.

apart from the syntax and arguments,
findNearestItem() and findNearest(hero.findItems)
always return the same result, correct?
If so, then what’s the point of having two different functions for this?

findNearestItem() and findNearestEnemy() are really meant for people starting to learn how to code, findNearest() however is more flexible and useful for more advanced coders. For example: if you want to find the nearest projectile out of an array of projectiles (hero.findEnemy/FriendlyMissiles) you can use hero.findNearest(hero.findEnemyMissiles()) and it’s a lot more efficient than using a hero.findNearestEnemyMissile function and a function to return an array of projectiles (hero.findEnemyMissiles) which would both be necessary, instead you can use hero.findNearest(hero.findEnemyMissiles()) and hero.findNearest(hero.findHazards()) and hero.findNearest(hero.findByType(“thrower”)) all using the same function: hero.findNearest() which saves the programmers time in creating the game and coders learning with the game.
I hope this helps you understand what I’m trying to say.

1 Like