Turning a graphic's index into a variable?

Hello! I'm using the following script call to in order to grab the party leaders graphic name, so I can go back and fourth between a "menu" map and the regular map.
$gameParty.leader().actorId()).characterName()

It works, but I have yet to find a way to also grab the index? So currently, this method would only work with sprites using a single sprite set, right? So, is there a specific script call I can use to turn the graphic index into a variable as well, and give me control over a full 8-set sheet?
$gameParty.leader().actorId()).characterName()
I assume it's just a typo, but this script call will cause an error: either unexpected token ) (mismatched brackets) or characterName is not a function (because you're invoking it on a number, the actor ID). 😅

To get the leader's spritesheet name:
JavaScript:
$gameParty.leader().characterName()
To get the leader's character block index:
JavaScript:
$gameParty.leader().characterIndex()
You can use these in the Control Variables > Script box.

To reassign the values afterwards, you can try this in a Script command:
JavaScript:
var name  = $gameVariables.value(1);
var index = $gameVariables.value(2);
$gameParty.leader().setCharacterImage(name, index);
This will set the leader's map sprite to the sheet with name stored in game variable 1, and the character block stored in game variable 2. Change the numbers as needed for your situation~

Note that this system will be more complicated to implement if the player is allowed to change the order of the party while on your menu map. In case it helps, you can reference other party members by their position in the party. For example, the leader is position 0, so these two lines are equivalent:
  • $gameParty.leader().characterName()
  • $gameParty.battleMembers()[0].characterName()
(I've used battleMembers here because that's how the core scripts decide who to show on the map.)
This is perfect! Luckily I'm just using it to create a "menu" and turns the players sprite into a cursor while they're on said map. So it just needs to work on the party leader.

Thanks a ton!

Original thread: https://forums.rpgmakerweb.com/threads/turning-a-graphics-index-into-a-variable.136785/