(Solved) Switch statement syntax confusion

Hello!

So, short story, I've got a common event that causes the luck stat of a party member to be added to a game variable. There are six possible party members, and only one of them can be in the party at a given time. The plan is to use a switch statement to figure out which character is in the party, and use that to determine who's luck stat to use. Here's what I've got so far:


; switch ($gameParty.leader().actorId() == ID) {

case 0:

$gameVariables.setValue(2, $gameVariables.value(2) + $gameActors.actor(1).param[7] );

break;

case 1:

$gameVariables.setValue(2, $gameVariables.value(2) + $gameActors.actor(2).param[7] );

break;

// and so on


Here's the problem: I barely understand any of this stuff. I wrote it mostly through copy pasting stuff from RMMV Script Calls and guessing the rest. I don't want to drag someone into teaching me all of javascript, I just need to know how I'm supposed to change what I have so it'll work, and I can use that to figure out the rest.

Thank you for your time!
A switch statement is not a conditional statement - you don't have == <something> as part of the statement.

Here's an easier way:

Control Variables: [0050: junk] = Game Data > Party > Member 1's > Actor ID
Control Variables: [0002: ???] += Script: $gameActors.actor($gameVariables.value(50)).param[7]


I'm not sure if the param[7] is correct - I'm just going by what you've got.

What we're doing is using the event commands to get the leader's actor id into one variable, then use that variable to look up the actor object and get the desired value, incrementing variable 2 with that value.

You can do a lot with event commands, especially with Control Variables, without having to resort to writing scripts.


You can even reduce it to one line:

Control Variables [0002: ???] += Script: $gameParty.leader().param[7]
Okay, now I'm really confused. I set up a common event with this code and added parts before and after, initialising variable 2 at 0 and checking if it is at 10 afterwards (10 being the current party leader's luck stat). The if statement I have set up to see if variable 2 is equal to 10 tells me it's not, and I have no earthly idea why.

edit: oh wait hang on I just noticed why one sec

edit 2: Nope, false alarm. I still have no idea what it's playing at. It's just saying something about "syntaxError: unexpected end of input."

edit 3: tried that one line of code solution, and, well, it's still telling me that var 2 isn't 10 but at least it isn't telling me about syntax errors anymore.

edit 4: Okay, I tested to see if $gameParty.leader().mhp would yield the party leader max HP, and it DID, so I think the problem has got to be with that param[7] part. Now if I only knew where to find what it should actually be...
I believe it should be .param(7) not .param[7] because param is actually function not an array (or .params(7) not sure if there is an s or not)

or you know, since it will always be LUK stat, why not just use .luk (same as how you used .mhp for your test)
I did not know I could use .luk. That makes things much much much much easier. It works like a dream now. Thank you both 🙂

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-switch-statement-syntax-confusion.102548/