How to find actor ID from actor name.

Hi, what I am trying to do is little advanced for my current skills.
I am trying to make player choose actors to put in his party as a choice, but I wanted the player to have some infos about this actor so I am using SRD HUD Maker plugin to show some stats of the actor using this code:
1728055430952.png

Choice Index ID is variable40 and the + 10 is because the first actor I set ID is 10 and the first index ID is 0.

It worked fine as I want to but what I didn't thought about is actors who die in battle will not be showin in the choices using YEP_X_ExtMesPack1 plugin to hide the choice of dead Characters.
So if actor id 10 is dead and his choice is hidden, actor id11 name will take his place, it will still function right for picking the actor the player want to pick but it will show the stats of actor10 because the choice index still 0 + 10.

I have 2 ways to fix this problem, the first is to making the choice of dead party members disabled not hidden but because I am having 50 or even more party members I prefare to hide over disable the choice.
The second way is much better but not sure if it possible.
With a script I try to find the choice name, find if that name is the same of a party member name it get the actor id and put it in a variable (But thinking about it now even if this is possible, if player named 2 actors the same name there will be a problem.)

Now I also thought about doing choices with script call if there is a way to make each choice change variable when player hover on it.

Is there a way to do this?
I think you're going about this in a more complicated way than you need to.

For one thing, that first line of script isn't doing anything. It's like you opening your front door and shouting, "5!" 😉

For another, I think there are existing plugins to make this all much simpler for you - have you looked into SRD's Actor Select?

You can find actor IDs by their name, but as you say there's a drawback if you're allowing the player to name all of the characters. It will either:
- only find the first instance of a given name
or
- return an array of actor IDs with that name, and your system wouldn't have any idea what to do from there

Code:
for (let i = 1; i < $gameActors._data.length; i++) 
{
    if ($gameActors._data[i] && $gameActors._data[i].name() == "Harold") 
        $gameVariables.setValue(60, i);
}[code]
will give you the ID of the first actor named Harold.

(I don't understand why find() and findIndex() fail here - anyone have any insight?)
I think you're going about this in a more complicated way than you need to.

For one thing, that first line of script isn't doing anything. It's like you opening your front door and shouting, "5!" 😉

For another, I think there are existing plugins to make this all much simpler for you - have you looked into SRD's Actor Select?

You can find actor IDs by their name, but as you say there's a drawback if you're allowing the player to name all of the characters. It will either:
- only find the first instance of a given name
or
- return an array of actor IDs with that name, and your system wouldn't have any idea what to do from there

Code:
for (let i = 1; i < $gameActors._data.length; i++)
{
    if ($gameActors._data[i] && $gameActors._data[i].name() == "Harold")
        $gameVariables.setValue(60, i);
}[code]
will give you the ID of the first actor named Harold.

(I don't understand why find() and findIndex() fail here - anyone have any insight?)
Yeah I need to find a different way because using names will have problems and I have like 50 actor for now and I could add more so looking for each actor name will need alot of work, esle I scrap this and move on.
The system work fine for me it just the hover effect I wanted to have didn't work.
Selecting actors is not just to add to party but also to place them in different locations and things like that else I would let the player use the basic selecting members.
The plugin I linked you to doesn't have anything to do with adding to the party - it displays a screen with the actors and you select one to store its ID in a variable, which is exactly what you said you wanted.

But I haven't used it, so it might not be useful for your purposes.

You could use something like Eli's Escape Codes so that for each choice you're setting a variable to the actor's ID; using an escape code in the choice to evaluate JavaScript for that actor's name, e.g.
Code:
$gameActors.actor($gameVariables.value(40)).name()
then you have the ID in a variable to reference with your HUD, instead of trying to calculate it off of the choice index.
The plugin I linked you to doesn't have anything to do with adding to the party - it displays a screen with the actors and you select one to store its ID in a variable, which is exactly what you said you wanted.

But I haven't used it, so it might not be useful for your purposes.

You could use something like Eli's Escape Codes so that for each choice you're setting a variable to the actor's ID; using an escape code in the choice to evaluate JavaScript for that actor's name, e.g.
Code:
$gameActors.actor($gameVariables.value(40)).name()
then you have the ID in a variable to reference with your HUD, instead of trying to calculate it off of the choice index.
I tried the plugin it work like you said but there is many functions I am doing with the project the plugin won't help with, if I am gonna use it I would need to remake the full project.

The 2nd option I didn't understand, my goal is when player hover on the name of the actor in the show choice window I display the actor stats.

Example of what I am trying to do:
1728070788437.png

Original thread: https://forums.rpgmakerweb.com/threads/how-to-find-actor-id-from-actor-name.172364/