Get actor ID from position in party

BEFORE YOU REPLY: I am not looking for something like
  1. $game_variables[1] = $game_actors[3].index
Expand to see the code.


No. What that script does is, given the actor's ID, the game will figure out it's position in the party.

I would like a script that does the vice versa of that in VX: Given the position in the party, the game will figure out what the ID of the actor occupying that slot is. I don't know if this already exists, I tried googling it, but I came up with nothing.
You have to check $game_party.members (or $game_party.actors for XP, just for information), which holds your current party's employees. To check for the id in a specific spot, use this:
  1. $game_party.members[3].id # returns ID of party actor #3
Expand to see the code.

Please ask if you have any more questions regarding this.


Also, this belongs to RGSS Support, not Script Request, as it's a function question, not a request for a whole system or whatnot.
BlueScope wrote:
You have to check $game_party.members (or $game_party.actors for XP, just for information), which holds your current party's employees. To check for the id in a specific spot, use this:
  1. $game_party.members[3].id # returns ID of party actor #3
Expand to see the code.

Please ask if you have any more questions regarding this.


Also, this belongs to RGSS Support, not Script Request, as it's a function question, not a request for a whole system or whatnot.


Hmm. Well I tried
  1. $game_variables[102] = $game_party.members[1].id
Expand to see the code.


but that doesn't seem to be working. It doesn't put a numberical value into the variable and just gives me a bunch of glitchy stuff.
Hm... for all I know, VX isn't quite as easy on setting $game_variables as XP was... for example, you can't set them to hold strings anymore. However, as the ID is a pure integer, I wouldn't know why it doesn't work... to be sure, put this instead to check on the 'pure' output before any special rules will be applied:
  1. p $game_party.members[1].id
  2. $game_variables[102] = $game_party.members[1].id # very same line
Expand to see the code.

If that outputs a readable value, try this:
  1. $game_variables[102] = $game_party.members[1].id.to_i # not very same line
Expand to see the code.


Other than that, it goes without saying that you have to have an actor in your party to do this... but I guess you figured that out by yourself ^^" (reminds me you might want to check for that when executing your script...)

If that doesn't work, please let me have a look at the 'glitchy' stuff.
Also remember that indexes start at 0.

So the first member is index 0, the second index 1....

ID of the first member:
$game_variables[102] = $game_party.members[0].id
True, I was thinking database items, which start at 1 ^^" Thanks for the correction.
This applies for the variables, though: $game_variables[102] will actually be #102 in the variable list.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=71179