I’ve got actors who have selectable main classes and subclasses in my project, and I’m trying to figure out how to check an actor’s current subclass so I can use the subclass ID as a condition for various events, evals, etc.
I’ve seen the script call below recommended elsewhere to accomplish this, but every time I use it, I get errors as soon as the script is called:
a.subclass().id === x
Where x is the subclass ID. So for example, I tried something like this with Yanfly’s Auto Passive States plugin:
<Custom Passive Condition>
if (user.subclass().id === 1) {
condition = true;
} else {
condition = false;
}
</Custom Passive Condition>
The above code (written in the State notebox) caused the game to immediately crash when an actor who had both the passive state and the designated subclass went into battle.
I also get errors when trying to use the code in battle events with this format:
$gameActors.actor(x).subclass().id === y
Where x is the actor ID and y is the subclass ID. The consistent errors lead me to believe there’s something fundamentally wrong with the way I’m using the script call, rather than the specific events or plugins I’m trying to use it with.
Can anyone give me some insight into where I’m going wrong? Thanks!
How to check an actor’s subclass?
● ARCHIVED · READ-ONLY
-
-
Actors don't have subclasses in default RMMV so if you're using a plugin you should say which one and provide a link.
-
It’s Yanfly’s Subclass plugin, sorry (http://yanfly.moe/2015/11/29/yep-34-subclass/).
Yanfly’s Class Change Core and Subclass plugins don’t list any JS functions in their help files, so the script call I described above is all I have to go on. It was mentioned in a few older threads I found about Yanfly’s Subclass plugin, but I haven’t been able to get it working properly. -
I'm not using Yanfly's Auto Passive States but I'm using a similar script to evaluate whether skills are available based on the actors subclass.
Spoiler<Custom Show Eval>
if (user.subclass() !== null) {
if (user.subclass().id === 6) {
visible = true;
} else {
visible = false;
}
} else {
visible = false;
}
</Custom Show Eval>
The only difference is I have the statement nested to prevent errors in the console when the character isn't using a subclass (it ends up displaying the skill if no subclass is selected without this), so I'm inclined to say the issue might not be with your script.
I've tried running your second code as well and it appears to evaluate fine, again only throwing errors when there is no subclass selected. -
Here's the definition of the subclass() method:
Code:Game_Actor.prototype.subclass = function() { if (this._subclassId === undefined) this.initSubclasses(); return $dataClasses[this._subclassId]; };
So you'd be able to use the actor property _subclassId directly also. -
Edit: I was able to figure this out. I made script to check an actor's subclass and I'll add it below.
I realize I'm trying to revive a dead thread, but I just wanted to follow up on this. I have some javascript skill, but I'm still not certain how I would use the code. I want to check to see what subclass an actor has and store it in a game variable. So I assume it would,be something like $gameVariable.setValue(x, Actor._subclassId)
Code:
Code:Game_Actor.prototype.subclass = function() { if (this._subclassId === undefined) this.initSubclasses(); return $dataClasses[this._subclassId]; };