Need help with a few lines of code.

So, essentially, what I'm trying to do is:

If the actor has a specific item equipped, it will allow the actor to learn a skill (which is what "value = true" is for).

Otherwise, if they do not have this specific item equipped, it won't allow the actor to learn the skill.

This is the code I'm trying to work with:

<Learn Require Eval>

righthand = $game_actors[actor_id].equips[0];

if !right_hand.name.eql?(""Broadsword""){

value = true

} else {

value = false

}

</Learn Require Eval>

​
I don't think the plugin is causing the issue and I think it's just more or less how I'm writing the code (I'm a complete newbie at JS). But the plugin is Yanfly Skill Learn System located here.
There's a more streamlined way to write this code. Try this:

<Learn Require Eval>

value = user.equips[0].name === 'Broadsword';

</Learn Require Eval>

Since you haven't done a lot of coding yet, I'll break it down a bit:

user refers to the actor learning the skill

equips refers to current equipment worn; [0] is the first slot, usually the weapon

name is, of course, the name of the weapon, but two things to note:

1. It may require name() instead of name; not 100% on that

2. Using id instead of name may work better, in which case it looks like this

<Learn Require Eval>

value = user.equips[0].id === ID# of weapon;

</Learn Require Eval>
I tried all three different methods you gave me but when I run it in-game, it returns an error along the lines of "cannot read property of name of undefined (or id in the case of the id version)".

I know in the plugin it said in order for the note tag to work, the 'value' should always return as true? I'm not 100% sure if that is the problem.
After some digging, I found this:

<Learn Require Eval>

value = this._actor.equips[0].name === 'Broadsword';

</Learn Require Eval>

The code that checked requirements didn't have user as a recognized variable. I'm not certain that this is right either, but try it and see what happens.
If it's just one specific item, try:
Code:
<Learn Require Eval>
value = user.hasWeapon($dataWeapons[123]);
</Learn Require Eval>
Replace 123 with the ID of the weapon you want to check for. =)

As an aside...user actually is defined in Window_SkillLearn.prototype.getEvalLine. I think the issue with @shockra's attempts was a misnamed equips array:
  • _equips is the array of equipped items
  • equips() is a getter function for _equips
I opted to use the hasWeapon function (which returns true iff that actor has the weapon equipped) just because it's neater. =P
If it's just one specific item, try:
Code:
<Learn Require Eval>
value = user.hasWeapon($dataWeapons[123]);
</Learn Require Eval>
Replace 123 with the ID of the weapon you want to check for. =)

As an aside...user actually is defined in Window_SkillLearn.prototype.getEvalLine. I think the issue with @shockra's attempts was a misnamed equips array:
  • _equips is the array of equipped items
  • equips() is a getter function for _equips
I opted to use the hasWeapon function (which returns true iff that actor has the weapon equipped) just because it's neater. =P

Yeah, I never checked if the equips part was correct. @caethyril's version looks right.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-a-few-lines-of-code.94891/