[MZ]How to get actor skill ID?

Hi everyone, im trying to get actor skill id, i used this code:

$gameActors.actor(1).skills().indexOf($dataSkills[1])

but it is showing 0 value.
Actually the skill id of actor 1 is 5.
Can you explain a bit more?
Can you explain a bit more?
I want to get actor skill ID value and put into variable
so, the actor only ever has 1 skill?

Code:
$gameVariables.setValue(1, $gameActors.actor(1).skills()[0].id);

will set the first skill in the actors list.
index starts at 0 and may change if other skills are added to the actor.

If you want to know if the actor has a specific skill

Code:
$gameActors.actor(1).skills().contains($dataSkills[x]);
returns true/false
x being the skill database number
so, the actor only ever has 1 skill?

Code:
$gameVariables.setValue(1, $gameActors.actor(1).skills()[0].id);

will set the first skill in the actors list.
index starts at 0 and may change if other skills are added to the actor.

If you want to know if the actor has a specific skill

Code:
$gameActors.actor(1).skills().contains($dataSkills[x]);
returns true/false
x being the skill database number
Still shows 0
Yes, the actor has 2 skills
can you include screenshots of your actor database, skill database, and event where code is used
can you include screenshots of your actor database, skill database, and event where code is used
I noticed the error now, two of the same skills on database.
Now worked!
Thank u som much
sorry m8, I was asking for your DATABASE, actor tab and skills tab. please
sorry m8, I was asking for your DATABASE, actor tab and skills tab. please
This problem was solved.
But i want to ask u another favor
When I put ID 3, which would be the ID of skill 4, and the actor doesn't have the skill, that is, the value is null, I get this error...

Screenshot_4.png

Screenshot_5.png


How could I not get this error?
This problem was solved.
But i want to ask u another favor
When I put ID 3, which would be the ID of skill 4, and the actor doesn't have the skill, that is, the value is null, I get this error...

View attachment 234247
View attachment 234248

How could I not get this error?
That's because you're trying to access a property of an element in the array that doesn't exist. There's no object there to get the id of. You can use a null-chaining operator and logical or to avoid this:

$gameVariables.setValue(1, $gameActors.actor(1).skills()[3]?.id || 0);
That's because you're trying to access a property of an element in the array that doesn't exist. There's no object there to get the id of. You can use a null-chaining operator and logical or to avoid this:

$gameVariables.setValue(1, $gameActors.actor(1).skills()[3]?.id || 0);
Wow amazing! Worked! thanks

Original thread: https://forums.rpgmakerweb.com/threads/mz-how-to-get-actor-skill-id.149308/