Get Actor's Index based on dynamic Actor ID in battle

Hey guys!


This one seems simple but I just can't figure it out.


How do we store Index of an Actor with Actor ID X in variable? Where X is an another game variable.


It is very easy if the X is constant but how if it isnt?


I dont think $game_actors[$game_variable[55]].index will work....


Please help, thanks!
Something like this, I guess.


$game_variables[1] = Actor_ID # ID of actor whose index we want.
$game_variables[2] = Actor_Index # Where we'll store the index.
$game_party.members.each do |member|
$game_variables[2] = member.index if member.id == $game_variables[1]
end


In battle, an actors index will be based on their position in the party, starting from 0.


The problem with using global variables is that they default to 0, so if the Actor ID


isn't present in battle, the index value would default to 0 (the first member).



Its not difficult to get around this drawback, but without some context into what you're


attempting to accomplish, I'm not sure if it's even necessary.
Something like this, I guess.



$game_variables[1] = Actor_ID # ID of actor whose index we want.
$game_variables[2] = Actor_Index # Where we'll store the index.
$game_party.members.each do |member|
$game_variables[2] = member.index if member.id == $game_variables[1]
end


In battle, an actors index will be based on their position in the party, starting from 0.


The problem with using global variables is that they default to 0, so if the Actor ID


isn't present in battle, the index value would default to 0 (the first member).



Its not difficult to get around this drawback, but without some context into what you're


attempting to accomplish, I'm not sure if it's even necessary.

Alright, thanks! I got the way around this method actually... But thanks for you reply
I dont think $game_actors[$game_variable[55]].index will work....



That's actually almost exactly what you do.  Except it's $game_variables (plural) rather than $game_variable.


If your actor ID is in variable 55, that will return the spot in the party lineup that the actor occupies.  Remember the first person / leader is 0, not 1.
Alright thanks! (I haven't tried it because I found a better method for my game  than doing  this, but still maybe I'll need that sometime in the future)

Original thread: https://forums.rpgmakerweb.com/threads/get-actors-index-based-on-dynamic-actor-id-in-battle.69014/