MZ Need Help Pulling an Array of Skills from Current Class

Good Morning All!

I am struggling to adapt an existing script I use.

I use

const armSkills = actor.equips() .filter((equip, index) => index === 0) // Armoire Skills .flatMap(equip => { if (equip && equip.traits) { return equip.traits.filter(trait => trait.code === 43); } else { return []; } }) .map(trait => { const armSkill = $dataSkills[trait.dataId]; const apValue = extractApValue(armSkill.note); // Extract the AP value from the note tag return { id: trait.dataId, // Add the skill ID to the result iconIndex: armSkill.iconIndex, name: armSkill.name, apValue: apValue // Add the extracted AP value to the result }; }); const armskillIcon1 = armSkills[0] ? armSkills[0].iconIndex : 0; const armskillName1 = armSkills[0] ? armSkills[0].name : ""; const armskill1Id = armSkills[0] ? armSkills[0].id : 0; // Get the ID of the first skill, or set it to 0 if not available const armskill1AP = armSkills[0] ? armSkills[0].apValue : ""; // Get the AP value of the first skill, or set it to 0 if not available

To check the Skills traited to the specified equipment slot.

What I'd like to do is be able to do the same for actors class actor.currentClass() and subclass actor.multiclass(2)

I cannot for the life of me figure out how to.


Help?
Holy cow. Um.

So this:
const armSkills = actor.equips() .filter((equip, index) => index === 0) // Armoire Skills
"filtering" an array by index 0 is the same thing as just directly referencing the element in index 0. Then there's no point in flatMap() because filtering by index 0 can only produce one object. That whole behemoth thing you have typed before map is just
Code:
actor.equips()[0]?.traits.filter(trait => trait.code==43)

Then you can add the map() stuff onto that...I haven't gone through the rest of what you have in there to try to see what you're achieving with it, but it can probably be simplified.

What I'd like to do is be able to do the same for actors class actor.currentClass() and subclass actor.multiclass(2)

I cannot for the life of me figure out how to.
currentClass() returns the database entry, so you should be able to access currentClass().traits and do the exact same operations. I don't know what the VisuStella multiclass() method returns, but it would be logical to also return the Class object.
Holy cow. Um.

So this:
"filtering" an array by index 0 is the same thing as just directly referencing the element in index 0. Then there's no point in flatMap() because filtering by index 0 can only produce one object. That whole behemoth thing you have typed before map is just
Code:
actor.equips()[0]?.traits.filter(trait => trait.code==43)
Then you can add the map() stuff onto that...I haven't gone through the rest of what you have in there to try to see what you're achieving with it, but it can probably be simplified.
So this?:

const armSkills = actor.equips()[0]?.traits.filter(trait => trait.code==43) .map(trait => { const armSkill = $dataSkills[trait.dataId]; const apValue = extractApValue(armSkill.note); // Extract the AP value from the note tag return { id: trait.dataId, // Add the skill ID to the result iconIndex: armSkill.iconIndex, name: armSkill.name, apValue: apValue // Add the extracted AP value to the result }; });


I'll take a crack at doing the swap in for currentClass and multiclass(2) and see how it goes then



Also as an aside, that flatmap was a leftover from when I wasn't using === 0 for other versions of that script. Just never changed lol

Update: got primary class working fine. Ty @ATT_Turan , just gotta work out the proper call for the multiclasses
Sure. You can trim a few lines off your code by just putting those values after armSkill and apValue instead of making variables that you only reference once...but it's not hurting anything if there's a reason you find it easier to look at or something.
This thread is being closed due to being solved. If you need it reopened, report it to let us know why. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/need-help-pulling-an-array-of-skills-from-current-class.162937/