Need help with a few lines of code.

porsef

Warper
Member
Joined
May 5, 2018
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMV
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.
 

shockra

Slightly Crazy Programmer
Veteran
Joined
Feb 16, 2016
Messages
444
Reaction score
208
First Language
English
Primarily Uses
RMMV
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>
 

porsef

Warper
Member
Joined
May 5, 2018
Messages
4
Reaction score
0
First Language
English
Primarily Uses
RMMV
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.
 

shockra

Slightly Crazy Programmer
Veteran
Joined
Feb 16, 2016
Messages
444
Reaction score
208
First Language
English
Primarily Uses
RMMV
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.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,117
Reaction score
1,525
First Language
EN
Primarily Uses
RMMZ
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
 

shockra

Slightly Crazy Programmer
Veteran
Joined
Feb 16, 2016
Messages
444
Reaction score
208
First Language
English
Primarily Uses
RMMV
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,476
Members
137,824
Latest member
dobratemporal
Top