MV check class of actor in a formula

Hi, everyone,

I've been looking for info for a while and haven't found an answer that works :

I use this code to trigger special effects only if it's actor #1, 4, 6 or 10 and another effect if it's not

JavaScript:
if ([1, 4, 6, 10].includes(b.actorId())) { AudioManager.playSe({name: 'Buzzer1', volume: 100, pitch: 100});$gameParty.gainItem($dataItems[8], 1); 0; } else { 50; }

this formula works perfectly, being a beginner in javascript, I'm already happy :LZSlol: but...

I'd like to go through the class instead the actorID but I don't know which code to use. I've tried :

Code:
b.ClassId()
b.CurrentClass()
b.actor.ClassId()
b._classId

But it doesn't work, I don't have the right synthax. I found this document to try and help me, but I didn't find (or understand) what I was looking for...

If anyone can help me, that would be great, thanks 🙂
I think you are referring to these:
JavaScript:
b.currentClass().id;
b._classId
Example:
JavaScript:
b._classId === 1 ? (SoundManager.playBuzzer(), $gameParty.gainItem($dataItems[8], 1)) : 50
Or
JavaScript:
b.currentClass().id === 1 ? (SoundManager.playBuzzer(), $gameParty.gainItem($dataItems[8], 1)) : 50
its a pretty good habit to keep the console open while testing stuff. it helps troubleshoot errors if anything causes one
also the general naming convention is camel case with the first letter bring lowercase.

.classId() isnt an actor function
.currentClass() is, but it returns the class's data entry. youd have to check its id from there
.actor() is a function to get the database entry. so missing parentheses, classId() still isnt a function, but also id assume that if the class changes at all in the game, that wont be reflected
._classId should have worked if the target was that class, but if you accidentally capitalized anything but the "I" it wouldnt
I found this document to try and help me, but I didn't find (or understand) what I was looking for...
That document is formatted to give you the code versions of event commands. Since there isn't one that directly references class ID, it's not on there.

If you're comfortable with JavaScript, all of this is in the core scripts of course - just reading through Game_Actor, the data type for actors, would show in one of its first methods initializing a _classId property:

1730056923438.png


And then, reading further down, you'd see it referenced in several other places, such as:

1730057087996.png


There's also this site, which has all the information from the core scripts in an organized, hyperlinked way:
._classId should have worked if the target was that class, but if you accidentally capitalized anything but the "I" it wouldnt
it works, TY ! 😅
If you're comfortable with JavaScript, all of this is in the core scripts of course - just reading through Game_Actor, the data type for actors, would show in one of its first methods initializing a _classId property:
That the problem 😀 i'm a beginner, but I try to understand and I test a lot of things, but sometimes, i'm stuck 😀 😢
Thx for help, guys 🙂
i'm a beginner, but I try to understand and I test a lot of things, but sometimes, i'm stuck
I say this often - if you're interested in this side of RPG Maker, it would be worth your time to do JavaScript tutorials. I like the w3schools, starting with the Statements chapter, but there are many online courses, actual books, actual courses at a local school, etc.

Just copying and pasting things around and trying stuff that may or may not work teaches you very little, from a brain learning viewpoint. It's much more effective to actually follow explanations for a progression of content so you're learning what you're doing, why, and understanding it.

That way, once you progress to the point where you're doing stuff like you see in the RPG Maker code, you can just read and follow that code and understand what's going on without having to guess.

Original thread: https://forums.rpgmakerweb.com/threads/check-class-of-actor-in-a-formula.172869/