RMMV Seeking JS help on how to use skills() to display text

zelanius

Mechanics Freak
Veteran
Joined
Apr 29, 2020
Messages
170
Reaction score
47
First Language
English
Primarily Uses
RMMV
Hi All,

I am trying to display a list of skills an actor has and the corresponding skill level, through an event. I am currently using a combination of YEP Message Eval (to convert any JS to text) and Skill Master (to actually implement skill levels) plugins to try to achieve this. However, when I tried the following code, it just displays into text "[object, Object]" multiplied by the number of skills the actor has.
JavaScript:
$gameMessage.add("\\evalText<<$gameActors.actor(1).skills()>>");

All I am trying to do is simply display a list of skills that actor has, followed by the skill level of each skill. So, in the text box, it will appear as something like:
"Skill name of ID 10: Skill level x" - so if the skill name is Double Strike, and the skill level is 5, it will show "Double Strike: Skill level 5"

Appreciate any advise and thank you in advance!
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
6,965
Reaction score
4,797
First Language
English
Primarily Uses
RMMV
And there's no chance that the number of skills the player has is going to be larger than the size of the text window?

You can just do
Code:
var a=$gameActors.actor(1);
for (var i=0; i<a.skills().length; i++)
    $gameMessage.add(a.skills()[i].name + ": Skill level " + a.skillMasteryLevel(a.skills()[i].id));

That doesn't rely on any plugins (except the skill mastery that you said you want to display). Using the Message Eval is superfluous when you're starting with a script call.

That's useful when you want to display the results of code in a normal Show Text window - if you're starting with the JavaScript function to begin with, you can just put the information you want to be displayed textually.
 

zelanius

Mechanics Freak
Veteran
Joined
Apr 29, 2020
Messages
170
Reaction score
47
First Language
English
Primarily Uses
RMMV
hi @ATT_Turan , thanks for the prompt response! Your code works wonders! The only thing I added was the {} as I understand that I need to enclose the function after "for" in it, from what limited knowledge I have of JS.

Even if the lines exceed the text box, it will just continue on in the next text box, so I think it is fine. I can also modify the text box size since I use YEP's Message Core and its extension, which I might get to later once I get the core of the game working.
And there's no chance that the number of skills the player has is going to be larger than the size of the text window?

You can just do
Code:
var a=$gameActors.actor(1);
for (var i=0; i<a.skills().length; i++)
    $gameMessage.add(a.skills()[i].name + ": Skill level " + a.skillMasteryLevel(a.skills()[i].id));

That doesn't rely on any plugins (except the skill mastery that you said you want to display). Using the Message Eval is superfluous when you're starting with a script call.

That's useful when you want to display the results of code in a normal Show Text window - if you're starting with the JavaScript function to begin with, you can just put the information you want to be displayed textually.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
6,965
Reaction score
4,797
First Language
English
Primarily Uses
RMMV
hi @ATT_Turan , thanks for the prompt response! Your code works wonders! The only thing I added was the {} as I understand that I need to enclose the function after "for" in it, from what limited knowledge I have of JS.
Nope. Conditionals and loops will automatically apply to the next single code statement. Braces are only necessary if you have more than one statement to be executed, in which case you need to create a code block.
 

zelanius

Mechanics Freak
Veteran
Joined
Apr 29, 2020
Messages
170
Reaction score
47
First Language
English
Primarily Uses
RMMV
hi @ATT_Turan , I think I may have more than 1 statement, as the code did not work without brackets.

In any case, I managed to get the code to work the way I wanted it to after I tried to Frankenstein together some other lines of code I have seen elsewhere. Please let me share some screenshots here so you can see the end results of what I was trying to achieve.

I am very thankful for the response and help you provided as it got me to exactly where I want.
 

Attachments

  • a.skill to check skill levels.jpg
    a.skill to check skill levels.jpg
    77.6 KB · Views: 11
  • b.common event with code.jpg
    b.common event with code.jpg
    68.3 KB · Views: 10
  • c.text window showing skill levels.jpg
    c.text window showing skill levels.jpg
    88 KB · Views: 10

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
6,965
Reaction score
4,797
First Language
English
Primarily Uses
RMMV
hi @ATT_Turan , I think I may have more than 1 statement
...yes, you have more than one line of code :guffaw:
Your prior post didn't say you had added to the code I gave you, so when I typed it braces weren't necessary.

Please let me share some screenshots here so you can see the end results of what I was trying to achieve.
I understand you're getting things from various sources and don't necessarily know what it all means. Just a few bits of feedback:
- There's no reason to declare var active and then have a separate command where you push a list of values into it. Just declare the array that way in the first place: var active=[2, 3, 4, 5, 6, etc.

- There should be no reason to check if (skill && active...) There shouldn't be a situation where skill would be undefined.

- The last if conditional with the $gameMessage call I gave you is exactly what I was describing above. There's only one command after the if, so you don't need to add braces. It doesn't hurt anything, but especially in the Script command boxes where the number of lines is limited, it isn't needed.
 

zelanius

Mechanics Freak
Veteran
Joined
Apr 29, 2020
Messages
170
Reaction score
47
First Language
English
Primarily Uses
RMMV
@ATT_Turan , many thanks for the feedback. The reason I did the additional check, is because I have skills for which I do not intend to show the skill level (like passive skills), which is why I used the "active" check to check for only skill type IDs that should have skill level. Hope this clarifies the reason for the check.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
6,965
Reaction score
4,797
First Language
English
Primarily Uses
RMMV
The reason I did the additional check, is because I have skills for which I do not intend to show the skill level (like passive skills), which is why I used the "active" check
...that's not what I said. I said you shouldn't need the first condition, if (skill because the skill should never be undefined in that portion of the code.
 

zelanius

Mechanics Freak
Veteran
Joined
Apr 29, 2020
Messages
170
Reaction score
47
First Language
English
Primarily Uses
RMMV
@ATT_Turan , apologies on the delayed response. I was working off Yanfly's Spell Siphon Tips & Tricks to work out the code, but I have removed the first condition as per your recommendation. Thank you!
 

Latest Threads

Latest Posts

Latest Profile Posts

That moment when I am listening to another instructor teach and I am thinking…I have been doing this for almost 30 years…I know this material…I teach this material…and you are confusing the crap out of me…let alone the students. What the actual $&@#! are you talking about? :eek:
Help me make a choice. Which one makes more sense?
A. Range style 1.pngDiamond shape
B.Range style 2.png Square shape
I created a skill that can only be used if there are enemies within the player's range. When the player's range is 2, which one do you think is more appropriate to describe the range area?
Just once I would like to see some innocent person stumble upon a body in a crime show and instead of scream they sigh and just say, "Found another one."
Can we get like a RPGM VXA Pro edition with all the limits gone!!
I drew @TheoAllen 's Cecilia~

yVLlTmK.png

Forum statistics

Threads
128,360
Messages
1,193,880
Members
168,852
Latest member
xSeggy
Top