(Solved) Switch statement syntax confusion

Status
Not open for further replies.

marbeltoast

Your future fish emporer
Veteran
Joined
Nov 11, 2018
Messages
80
Reaction score
28
First Language
English
Primarily Uses
RMMV
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!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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]
 

marbeltoast

Your future fish emporer
Veteran
Joined
Nov 11, 2018
Messages
80
Reaction score
28
First Language
English
Primarily Uses
RMMV
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...
 
Last edited:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
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)
 

marbeltoast

Your future fish emporer
Veteran
Joined
Nov 11, 2018
Messages
80
Reaction score
28
First Language
English
Primarily Uses
RMMV
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 :)
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,842
Reaction score
5,225
First Language
Dutch
Primarily Uses
RMXP

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.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,049
Members
137,569
Latest member
Shtelsky
Top