Learn skill condition JS code help please

Hello. I'm using yanfly's skill learn core. I have a skill that I don't want available for learning to the class, unless a specific weapon is equipped.


<Learn Require Eval>
value = false;
var wpn = $game_actorId(this).weaponId().value;
if (wpn === 7) value = true;
</Learn Require Eval>


I know this doesn't work. I'm having a lot of trouble gleaning info I understand out of the js section of MV's help.


what's the correct code? It needs to work for any actor in the class and equipped with the weapon.
What is this?  If it's the actor, then something like this might work:


value = this.hasWeapon($dataWeapons[id])


where id is the weapon's id, with no leading zeros.
this = the actor you are checking the skills on.


with all my attempts including your code


value = this.hasWeapon($dataWeapons[id]) ;


I keep getting a "this" undefined error  while playtesting. menu>skills>actor    so before i even see the skill types with the learn skills option, I see the error.
Then 'this' must not be the actor you are checking the skills on.


What 'this' is and how it works would be entirely dependent on the plugin.  Does Yanfly state that you can use 'this' to refer to the current actor?


Edit: this is the Skill Learn window, not the actor at all.  Use the following:


value = this._actor.hasWeapon($dataWeapons[id])
value = this._actor.hasWeapon($dataWeapons[id]);


works great Thankyou. if i wanted to do something similar such as check to see if its a particular actor. would it be:


value = this._actor.actorId(id); ?


tested. nope
this._actor.actorId() will give you the id of the actor you're currently looking at.  If you want to see if that's actor 7, you'd do this:


value = this._actor.actorId() === 7


actorId() doesn't accept a parameter - it's returning the id of the actor you're running it on.
thank you. both your answers were very fast and spot on. 

Original thread: https://forums.rpgmakerweb.com/threads/learn-skill-condition-js-code-help-please.69622/