How to make a reference to a game_enemy from action?!

Hi everyone!! I wanted to know how can I reference a game_enemy and by that I mean one from the gameTroop array!
for example for actors you can do something like... action.subject().actor().id... store this id and then use....
$gameActors.actor(id);

what if I want to do this with enemies....
doing.... action.subject.enemy().id (get's me the $dataEnemy... id... I don't want that... hope you understand what I want 😀

NOTE: What i mean is there is not a unique Game_Enemy identifier :/
you'll need the index, not the ID - the ID is always the number from the database.


Can you describe why you want that? Because there are ways to reference the index by eventing (as soon as enemy commands are used in troop events, the commands correctly reference the enemy index and name the target), but that won't work for everything (and sorry, I don't know the javascript for the index myself)
if  'action.subject' is the enemy object you can do something like:


var index = $gameTroop.members().indexOf(action.subject)


$gameTroop.members()[index]


although this would just return the same object.


So it would be better if you said what you want, because to get the $dataEnemies data you need the Game_Enemy data. If you don't have the index you can't get the Game_Enemy from the $gameTroop.


With only the id of the enemy you can't also get it.


The value you need to reference an enemy in battle is the index.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-reference-to-a-game_enemy-from-action.56327/