How do I detect the skills of a variable actor?

If specify an actor, like actor 3, Does actor 3 have skills 4? it is simple.
but if a variable actor, like actor (variable 3) , Does variable 3 actor have skills 4?
I want to know how to use the script in the condtional branch.

And, How to know how many skills this actor has? I want to get this variable.
If this actor has more than 4 skills, he will no longer be able to learn new skills.
Hmm I'm not 100% sure what you mean, your wording is a bit confusing.
Assuming by 'variable actor' you mean having the ID of an actor stored in a variable...

$gameActors.actor($gameVariables.value(id)).skills() <-----This will return an array of objects representing the skills the character currently has.
Replace 'id' in the parenthesis with the variable number that is holding the Actor's id

$gameActors.actor($gameVariables.value(id)).skills().length <-----This is the current number of objects in the array, meaning the total number of the actor currently has learned.

For the conditional branch, you'd want to use the script box as the condition, and input the condition

$gameActors.actor($gameVariables.value(id)).skills().length < 4


Before I go further, is this the type of information you were looking for, or are we not talking about the same thing?
Hmm I'm not 100% sure what you mean, your wording is a bit confusing.
Assuming by 'variable actor' you mean having the ID of an actor stored in a variable...

$gameActors.actor($gameVariables.value(id)).skills() <-----This will return an array of objects representing the skills the character currently has.
Replace 'id' in the parenthesis with the variable number that is holding the Actor's id

$gameActors.actor($gameVariables.value(id)).skills().length <-----This is the current number of objects in the array, meaning the total number of the actor currently has learned.

For the conditional branch, you'd want to use the script box as the condition, and input the condition

$gameActors.actor($gameVariables.value(id)).skills().length < 4


Before I go further, is this the type of information you were looking for, or are we not talking about the same thing?
Almost so, I designed some skill reels. When the player uses it, I need to know if the character has this skill.
In the conditional branch, how can I judge?Determine if character 3 has skill 4, as follows:
value 1 = 3
$gameActors.actor($gameVariables.value(1)).skills(4)?
Ok, this is gonna be confusing, I'll explain it in detail if you'd like to know how each part is working, but for starters I'll just give you a method for getting this done.
Assume that Game Variable 1 is holding the Actor's ID
Assume that Game Variable 2 is holding the ID of the Skill you're checking for.

Create a conditional branch. It's condition will be a script call. The script call is as follows

$gameActors.actor($gameVariables.value(1)).skills().length <= 4

The above script call checks to make sure that 4 skills are learned. It may vary for you, depending on whether or not you have the Attack or Defend skills enabled for certain actors. My actor has Attack learned, so I used <= 4 instead of == 4, to accomodate for that. It may be different for your situation.

INSIDE of that conditional Block, create another conditional branch, with a script call condition. The script call is as follows

$gameActors.actor($gameVariables.value(1)).skills().filter(function(obj){return obj.id == $gameVariables.value(2)}).length == 0

This filters the array of skills and returns an array of all of the skills whose id matches the one stored in Game Variable 2. If the list is longer than
0, it means a match was found. Meaning this skill is already learned by that actor.


Finally, INSIDE of the that conditional block, you add the skill.
Select the Script command on the third tab of the event commands and enter the following

$gameActors.actor($gameVariables.value(1)).learnSkill($gameVariables.value(2));

The above line adds the skill with with the id store in variable 2 to the actor, whose id is stored in variable 1.

Make sense?

exampleEvent.png


EDIT: Since this is in the Learning JavaScript Boards, I'll gladly explain what's going on in detail there, for example the .filter method if you aren't familiar.
Ok, this is gonna be confusing, I'll explain it in detail if you'd like to know how each part is working, but for starters I'll just give you a method for getting this done.
Assume that Game Variable 1 is holding the Actor's ID
Assume that Game Variable 2 is holding the ID of the Skill you're checking for.

Create a conditional branch. It's condition will be a script call. The script call is as follows

$gameActors.actor($gameVariables.value(1)).skills().length <= 4

The above script call checks to make sure that 4 skills are learned. It may vary for you, depending on whether or not you have the Attack or Defend skills enabled for certain actors. My actor has Attack learned, so I used <= 4 instead of == 4, to accomodate for that. It may be different for your situation.

INSIDE of that conditional Block, create another conditional branch, with a script call condition. The script call is as follows

$gameActors.actor($gameVariables.value(1)).skills().filter(function(obj){return obj.id == $gameVariables.value(2)}).length == 0

This filters the array of skills and returns an array of all of the skills whose id matches the one stored in Game Variable 2. If the list is longer than
0, it means a match was found. Meaning this skill is already learned by that actor.


Finally, INSIDE of the that conditional block, you add the skill.
Select the Script command on the third tab of the event commands and enter the following

$gameActors.actor($gameVariables.value(1)).learnSkill($gameVariables.value(2));

The above line adds the skill with with the id store in variable 2 to the actor, whose id is stored in variable 1.

Make sense?

View attachment 125066

EDIT: Since this is in the Learning JavaScript Boards, I'll gladly explain what's going on in detail there, for example the .filter method if you aren't familiar.
That's good. If I want to set the number of skills at will, can I change it to:
$gameActors.actor($gameVariables.value(1)).skills().length <= $gameVariables.value(3)
Attack and defense are the basic skills in the game. Even if I don't design them, is this counted in the number of skills? If I want 4 skills, maybe I should set variable 3 to 6?
If the player uses the skill reels through the item menu, how do I know which character it is used on?
It really depends on how much the menu has been altered.
Traditionally, with the standard menu setup, an Actor doesn't come into focus in the item menu until AFTER you've selected an item. It brings up a window with the actors in your party listed.
For that window, while it's open, the call

$gameParty._actors[SceneManager._scene._actorWindow._index]

Will return the ID of the currently selected actor in that menu.

And yes, you could totally change the number of skills on the fly by using a variable, like your example.

Attack and defend and ANY skills listed in the skills database that are active on an actor will show up. You could do a bit more code to filter it out further, but if ALL of your actors have both attack and defense, one or the other, etc as long as they match, then yeah you could use whatever operation you needed or wanted to determine the number of skills to check for.
It really depends on how much the menu has been altered.
Traditionally, with the standard menu setup, an Actor doesn't come into focus in the item menu until AFTER you've selected an item. It brings up a window with the actors in your party listed.
For that window, while it's open, the call

$gameParty._actors[SceneManager._scene._actorWindow._index]

Will return the ID of the currently selected actor in that menu.

And yes, you could totally change the number of skills on the fly by using a variable, like your example.

Attack and defend and ANY skills listed in the skills database that are active on an actor will show up. You could do a bit more code to filter it out further, but if ALL of your actors have both attack and defense, one or the other, etc as long as they match, then yeah you could use whatever operation you needed or wanted to determine the number of skills to check for.
Yes, it's the standard menu setup.
I mean, when the player uses the skill reels, can I specify the ID of the character in a common event and then use the script you provided to determine the skill.
variable 1 = $gameParty._actors[SceneManager._scene._actorWindow._index]
Is right?
I'm not actually understanding what you mean by skill reels. When/where/how is this happening? The thing is, knowing which actor is selected at a given time can be different depending on the situation. The call you mentioned just now will only be valid inside of the item menu, when the character window opens.

I can't tell you how to specify the character until I know more about what's happening
I'm not actually understanding what you mean by skill reels.When/where/how is this happening?The thing is, knowing which actor is selected at a given time can be different depending on the situation.The call you mentioned just now will only be valid inside of the item menu, when the character window opens.

I can't tell you how to specify the character until I know more about what's happening
Ok, it's just a item. Players use this item to let the actor learn a specific skill. Like using a healing potion. But this requires a common event. So I have to know the player used this item to who.
Ahhh, i gotcha. As long as you are just using it as an item, and the regular item menu hasn't been altered by another plugin, then that script call will return the correct actor ID. It will return whichever actor is currently highlighted at the time of the script call.
Ahhh, i gotcha. As long as you are just using it as an item, and the regular item menu hasn't been altered by another plugin, then that script call will return the correct actor ID. It will return whichever actor is currently highlighted at the time of the script call.
But I don't know how to use it. What does "the call" mean?
But I don't know how to use it. What does "the call" mean?
It's essintally a script command. Like all the possible commands when your making an event. It's like that
You know what though, now that I better understand what you're doing, this won't work if you're putting it on a script command.
Specifically the
SceneManager._scene._actorWindow._index
call. Because you're calling it as a common event, by the time the common event is reached, that script call will have lost it's scope.

I'll have to think of another way, gimme a little bit. Unless @Oddball can bring it home for us.
It's essintally a script command. Like all the possible commands when your making an event. It's like that
Maybe this level is too high for me. I haven't found a way to apply it correctly.
But it doesn't matter, I can use the select item to solve the problem.
I'll have to think of another way, gimme a little bit. Unless @Oddball can bring it home for us.
Scripting is NOT my strong suit, but i'll try to think of something

Edit: That came quicker than excpected. Make a variable for each actor. Set each one to the number of skills they have. Make an event were they learn new skills. When an actor learns a new skill, increase the variable. Have a conditinal branch were if there variable is 4 or greater, they can't learn a new skill

You may need a script that increases the number of choices in a choice thing, and can be changed with variables/switches
You know what though, now that I better understand what you're doing, this won't work if you're putting it on a script command.
Specifically the
SceneManager._scene._actorWindow._index
call. Because you're calling it as a common event, by the time the common event is reached, that script call will have lost it's scope.

I'll have to think of another way, gimme a little bit. Unless @Oddball can bring it home for us.
If it's cumbersome to implement, don't worry about it. I can use the select item to solve the problem. Create a warehouse map, design each actor image (event), and let the player choose to use the item for these event. Although it is a bit cumbersome, but its good.
Thanks, You have helped me a lot.
Wait! I figured it out.

Create a .js document and save it to your plugins folder. In that document, save the following code

let spAlias_Game_Actor_consumeItem = Game_Actor.prototype.consumeItem;
Game_Actor.prototype.consumeItem = function(item){
$gameVariables.setValue(1, this._actorId);
spAlias_GameActor_consumeItem.call(this, item);

}


With this code, whenever you consume an item, the actor who consumed it will have their ID placed in variable 1. Its an archaic and quick fix, but with this code, you can just check Variable 1 (or change it in the code to whichever variable you prefer) when you run that common event. It will have the ID of the actor who just used an item from the Items menu.
Wait! I figured it out.

Create a .js document and save it to your plugins folder. In that document, save the following code

let spAlias_Game_Actor_consumeItem = Game_Actor.prototype.consumeItem;
Game_Actor.prototype.consumeItem = function(item){
$gameVariables.setValue(1, this._actorId);
spAlias_GameActor_consumeItem.call(this, item);

}


With this code, whenever you consume an item, the actor who consumed it will have their ID placed in variable 1. Its an archaic and quick fix, but with this code, you can just check Variable 1 (or change it in the code to whichever variable you prefer) when you run that common event. It will have the ID of the actor who just used an item from the Items menu.
I will try it, but there is still a problem.
If the actor already has this skill, the item will still be consumed.
Can I know which item the player used? Turn it into variable 4.
$gameParty.gainItem($dataItems[$gameVariables.value(4)], 1);
Can this be achieved?
The thing about contitinal branches is... they can check if an actor knows a skill. Try tinkering with my solution and see if you can get it to work like you want
What do you mean by which props the player used?
Also, are there many different items that are skill reels, or is there only 1 database item that is the skill reel?
Either way, I can think of some code to add, but I'd like to know that, first, as it will change what I need to write.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-detect-the-skills-of-a-variable-actor.113992/