Custom attributes for classes

Allow me to preface this by saying I know very little of programming.
I'm looking to assign a set of variables to existing classes; then the game will check which class is being used at game start. Whatever class the player chooses, those variables will change value according to that chosen class. Does that make sense?

So for one class, I assumed it'd go something like this...
Code:
if ($gameParty.leader().isClass($dataClasses[1]));
$gameVariables.setValue(8, 2);

Other classes would have a different value to that variable.

The problem is that the script doesn't seem to run automatically (I've made a plugin), only if I make it an event and interact with it. And then, only the second line of code has an effect. So regardless of whatever class is being used, the value of the variables always changes.
One issue you have there is that javascript ends the if code block after the semicolon...
so if (CONDITION) { CODE }; not your if (CONDITION) NOTHING ; CODE

In your code, both is correct:
JavaScript:
if ($gameParty.leader().isClass($dataClasses[1])) $gameVariables.setValue(8, 2);

JavaScript:
if ($gameParty.leader().isClass($dataClasses[1])) {
    $gameVariables.setValue(8, 2);
};
Also regarding the event. You have to set the event to autorun so you don't have to interact with it. Then it will be triggered automatically on entering the map. And don't forget to erase the event afterwards so it runs only once:
1720118880227.png
Hey Darai, thanks for the responses.
Nice, it works now.

What about running this from a plugin so it runs automatically every map?

Code:
function HowDoesThisWork (whatgoeshere) {{

        //King
        if ($gameParty.leader().isClass($dataClasses[1])){
        $gameVariables.setValue(8, 2)
        $gameVariables.setValue(9, 6)
        $gameVariables.setValue(10, 7)
        $gameVariables.setValue(11, 5)
        $gameVariables.setValue(12, 2)
        $gameVariables.setValue(13, 5);
        }
        //Alchemist
        if ($gameParty.leader().isClass($dataClasses[2])){
        $gameVariables.setValue(8, 1)
        $gameVariables.setValue(9, 7)
        $gameVariables.setValue(10, 4)
        $gameVariables.setValue(11, 5)
        $gameVariables.setValue(12, 3)
        $gameVariables.setValue(13, 6);
        }
}

This is what I have in a .js file. What am I missing?
I have to admit, I am not a good plugin-maker. Since I play with RPG maker just for 1/2 year. Do JS yes, design plugins not yet. But I would be against setting something to run automatically on every map through plugin anyway, since it can be easily done through events. What if you will want to change this one day for some single special map?

Well. From my experience, I would do it through an autorun event which will run a "Common Event".
So if you will not want it on some map you will simply not include that autorun event... and if you will want to edit it everywhere you will only edit that one common event.

But maybe there is more reason why you want to do it the hard, less transparent way. Anyway that issue with plugin structure is beyond my current skill, sorry.

For full details by "Run Common Event" I mean:
1) Create a common event in game database -> common events.
2) Run the event with event command "Common Event..." in the Flow Control box:
1720130918107.png
What if you will want to change this one day for some single special map?
In that case, if its a plugin, then Id put a check into either that function or the map transfer function that would run this one to see if some value somewhere is false before running any of that additional code. That way, you could do something like use a script call or flip a game switch before the map transfer into a special map and then flip the switch back when leaving that map

What am I missing?
You need to call your function somewhere within the process of changing maps
I don't understand why you're using code for this at all.

The built-in event command Conditional Branch can check what class any actor is, and Control Variables sets whichever variable you like to whatever value you like.

An event on a map set to Autorun with that stuff in it then Erase Event at the bottom will run every time you load the map.

Why are you trying to do this through JavaScript and a plugin?

Original thread: https://forums.rpgmakerweb.com/threads/custom-attributes-for-classes.170032/