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

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!
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.
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.
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.
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.
hi @ATT_Turan , I think I may have more than 1 statement
...yes, you have more than one line of code 🤣
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.
@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.
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.
@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!

Original thread: https://forums.rpgmakerweb.com/threads/seeking-js-help-on-how-to-use-skills-to-display-text.152983/