How get the index of an object in an array?

Hi !

Another day for another question ! :smiley:

Today i’m trying to find the array index of an actor in an array when a condition is complete.
Let me explain, when i press “D”, i want to destroy the nearest enemy to me, so i’ve created this maccro :

First, i get all of my blue enemies, then i compare get the distance between them and my hero and if it’s the lowest, i set the int “Nearest Distance” and only at this moment i want to get the actor with the nearest distance. i’ve tried to set the array index in a new int variable but it always give me “0” in my new variable. So the enemy destroyed is always the one at 0 in the index.

The last “Get” is supposed to give me the “actor” with the nearest distance to my hero and “Completed” return to the end of the maccro.

Thanks for your (future) help ! :slight_smile:

Your code not finding nearest, after it find current distance < nearest its break For Each Loop.

here the answer for your question

Thanks, it was so easy… How it’s possible that i forgot “Get distance to” ? u.u’