Help with super simple conditional variable show picture script??

I'm trying to script conditional branches checking if the variable = 1, 2 or 3, (in this case "cherries2")
and scripting a show picture for each result or 'else...'

I'm trying to sort out how to script the whole thing, because I've got like 1000 possibilities and will just be terribly long grind of clicking...

SOO! I am doing something stupid/silly, I know. I just don't know what.

I get "SyntaxError Unexpected token {"

I'm putting the following code:
If ($gameVariables.cherry2(1)){

$gameScreen.showPicture(17, “cherries21”, 0, 355, 303, 100, 100, 255, 0)}

else {If ($gameVariables.cherry2(2)){

$gameScreen.showPicture(17, “cherries22”, 0, 355, 303, 100, 100, 255, 0)}

else {if ($gameVariables.cherry2(3)){

$gameScreen.showPicture(17, “cherries23”, 0, 355, 303, 100, 100, 255, 0)}

in a parallel event as a script...

should there be an = sign in there like;
If ($gameVariables.cherry2(=1))
edit; nope lol no equal sign in there...

I think its definitely something with the conditional branching script or the game variables code part, var in there somewhere? - I am just not writing it properly... 🙁

edit: I don't see why '{' should be the problem 🙁 its clearly part of the conditional branch script... ?
Please give a screensshot of the event instead of retyping the text here.

"syntax error" is the computers way of saying you have a typo, and the number of times a typo was made in the event but automatically corrected when the poster retyped here is not countable...

additionally, sometimes it is the way you use the script command, again something only visible on a screenshot.
Please give a screensshot of the event instead of retyping the text here.

"syntax error" is the computers way of saying you have a typo, and the number of times a typo was made in the event but automatically corrected when the poster retyped here is not countable...

additionally, sometimes it is the way you use the script command, again something only visible on a screenshot.

Hey! Thanks for the response 🙂
Okay, here is a screen shot.
It's very minimal for the purpose of just testing the script function and making sure it works before writing it for 1000s of combinations.
Notes:
  1. I'm guessing cherry2 is the editor name you gave to one of the game variables? Or have you actually got a custom cherry2 method defined on Game_Variables? 😅

    Game variables are typically referenced by their unique ID. That's the number that appears next to the variable in the variables list. E.g. this gets the value of game variable ID 123:

    $gameVariables.value(123);

  2. It's if, not If.

  3. $gameVariables.value(123) === 1, not $gameVariables.cherry2(1).

  4. It should be "cherries21", not “cherries21”. I'm guessing you got your script calls from somewhere that automatically formatted neutral quotes into open/close quotes.

  5. Looks like the only difference in your branches is the picture name? If so, you could just form the picture name based on the variable value and use a single showPicture with that name.
Try this?

var variableId = 123; // <- edit this var value = $gameVariables.value(variableId); var picName = "cherries2" + value; $gameScreen.showPicture(17, picName, 0, 355, 303, 100, 100, 255, 0);
("cherries2" + value just sticks the number to the end of cherries2. That's how adding text works in JavaScript.)
There's a lot wrong with this. As Andar said, why are you trying to do this entire thing in JavaScript if you're not proficient with it? You can do a lot of this with the event commands and just insert a line or two in a script box where you need it.

Code:
If ($gameVariables.cherry2(1)){
This is completely wrong. What do you even want it to mean? The gameVariables game object doesn't have any "cherry2" function.

Code:
else {If ($gameVariables.cherry2(2)){
Why is the if inside the braces? It's not going to ruin your code, but there's also no reason for it. Also, you can't randomly capitalize code commands, it's "if". Again, cherry2 is not a method of gameVariables.

Code:
else {if ($gameVariables.cherry2(3)){
Same as above.
should there be an = sign in there like;
If ($gameVariables.cherry2(=1))
No, that would be even more wrong.

The format to check a variable's value is $gameVariables.value(id)

So this "cherry" stuff has nothing to do with what you do in script calls. It might be what you named your variables in the editor, but it's irrelevant in code. So to see if your variable is equal to the value 1, you would do if ($gameVariables.value(id)==1) where id is the actual number ID of your cherry variable.

Edit: Ninja caethyril 🤣
Notes:
  1. I'm guessing cherry2 is the editor name you gave to one of the game variables? Or have you actually got a custom cherry2 method defined on Game_Variables? 😅

    Game variables are typically referenced by their unique ID. That's the number that appears next to the variable in the variables list. E.g. this gets the value of game variable ID 123:

    $gameVariables.value(123);


  2. It's if, not If.

  3. $gameVariables.value(123) === 1, not $gameVariables.cherry2(1).

  4. It should be "cherries21", not “cherries21”. I'm guessing you got your script calls from somewhere that automatically formatted neutral quotes into open/close quotes.

  5. Looks like the only difference in your branches is the picture name? If so, you could just form the picture name based on the variable value and use a single showPicture with that name.
Try this?

var variableId = 123; // <- edit this var value = $gameVariables.value(variableId); var picName = "cherries2" + value; $gameScreen.showPicture(17, picName, 0, 355, 303, 100, 100, 255, 0);

("cherries2" + value just sticks the number to the end of cherries2. That's how adding text works in JavaScript.)

This is amazing, thank you so much!
I was pulling the script calls from (https://www.wikimoe.com/?post=108) and kind of general surfing of forums trying to sort out what I was doing right/wrong.
There's a lot wrong with this. As Andar said, why are you trying to do this entire thing in JavaScript if you're not proficient with it? You can do a lot of this with the event commands and just insert a line or two in a script box where you need it.

Code:
If ($gameVariables.cherry2(1)){
This is completely wrong. What do you even want it to mean? The gameVariables game object doesn't have any "cherry2" function.

Code:
else {If ($gameVariables.cherry2(2)){
Why is the if inside the braces? It's not going to ruin your code, but there's also no reason for it. Also, you can't randomly capitalize code commands, it's "if". Again, cherry2 is not a method of gameVariables.

Code:
else {if ($gameVariables.cherry2(3)){
Same as above.

No, that would be even more wrong.

The format to check a variable's value is $gameVariables.value(id)

So this "cherry" stuff has nothing to do with what you do in script calls. It might be what you named your variables in the editor, but it's irrelevant in code. So to see if your variable is equal to the value 1, you would do if ($gameVariables.value(id)==1) where id is the actual number ID of your cherry variable.

Edit: Ninja caethyril 🤣
Thanks for the response!

Yes, I realize thanks to Caethyril that the most major issue is the variable ID!!!
Not the editor's name for it...

I know I am not proficient in the script writing, but figured this "SHOULD" be pretty darn simple.
& and a good opportunity to learn lil something I should be able to handle.

It's hard for me to explain why its so important without blabbering about the whole "game"..
It's really just after manually eventing it, it would save SOOO much time for me to be able to write and edit the code itself in a text editor and paste it into the event, because it's 1000s of these different branches, - like a lot of dice rolling...
and otherwise, I break it up into different events so the event editor doesn't slow down, and I turn on music and I try to get into the rhythm of the clicking and entering the particular infos in each individual "nesting" I guess you call it and it just takes ages and you also don't want to accidentally numb out and do something silly and have to comb through the huge stack to see where you just slipped up entering the numbers wrong lol.
It's hard for me to explain why its so important without blabbering about the whole "game"..
just for your info:
game ideas themselves are practically worthless - it's the work of implementing them that gives them value.
as such trying to keep your ideas or mechanics secret will only make your work harder for not getting as much help.

because it's 1000s of these different branches, - like a lot of dice rolling...
then you're doing it the wrong way.
yes, with pure eventing you sometimes need a lot of conditional branches to check, but the entire purpose of scripts is to replace that by loops or indirect references. Using the same structure as needed for events in scripts does not help you in any way - especially not because the script box is size-limited and you will NOT be able to copy thousands of ifs into a single script box.

so either you tell us what this is about and we give you how to really do it, or you'll have to bungle around with incomplete scripting knowledge and make even more mistakes.
Maybe this helps a little bit with the Syntax:
Scriptcall List
just for your info:
game ideas themselves are practically worthless - it's the work of implementing them that gives them value.
as such trying to keep your ideas or mechanics secret will only make your work harder for not getting as much help.


then you're doing it the wrong way.
yes, with pure eventing you sometimes need a lot of conditional branches to check, but the entire purpose of scripts is to replace that by loops or indirect references. Using the same structure as needed for events in scripts does not help you in any way - especially not because the script box is size-limited and you will NOT be able to copy thousands of ifs into a single script box.

so either you tell us what this is about and we give you how to really do it, or you'll have to bungle around with incomplete scripting knowledge and make even more mistakes.

I did not mean because the mechanics need to be kept secret!
I just meant because I figure it is boring and a lot of words to describe it...

The game I'm making is for children, it's a lot of positive affirmations,
according to different choices...
Think of it like magic eight ball, meets fortune cookie, or like tarot ?
It's not any of those things, but the kid is going to be asked to think abstract things and questions,
and simple mechanic in terms of button pushing, choose which flower to water, like simple little choice scenarios...
The end of the game, is a receipt, like a results page,
I am using a lot of if the kid pressed those 5 buttons down, and then pressed that button twice- then this positive affirmation or the kid pressed that button first, so that triggered this on the "results" page"...

So my final map is where all these different variables are being processed into something meaningful for the kid and it has randomness to it, to be sure if they play it again and pressed the same sequences of buttons and choices, its still new and meaningful.
I've manually evented the majority of it...

but now I am getting to a tricker part where I'm comparing that if the kid pressed the button with the house on it and also pressed the button with an anvil on it, that is a specific relationship that leads to a result, that has some randomness to it, like 1-3,
but I have 23 of these symbolic buttons lol... and while I've thought it simple to just have comparisons of one to one... it still means I Have to branch out the possible comparisons of each one with each one, and x3 and we're in the 1000's of nesting branches.

I thought, okay, it must be a faster way to get this info down and into the editor, with less clicks if it's really just these variables? show picture... else these variables ? show picture blah blah blah
I think I'm just going to carry on doing it manually, because I'm not even sure how to ask the right question about the scripting that I thought could make it more efficient.

I attached the screenshots of the sort of manual eventing I mean and 2nd event screenshot is like an outline of a bunch more I still have to do, it just becomes a lot of repetitive clicking and pasting or inputting. I was thinking it could be faster, even if I still have to input a bunch of script calls because of my lack of proficiency- it would be more like click, paste, click paste, click paste, which would be faster than, click click adjust edit click click, next one or whatever.

So just leaving this here... in case someone has some final insight for me.

Thank you for the help thus far!
Besides the many mistakes, definitely important to understand the "value" after $gameVariables. is the function and isn't to replace with the variable 'value' lol.

I last tried this code; with no luck, and figure I should just get on with my manual eventing grind!
if $gameVariables.value(0024)=== 1{$gameScreen.showPicture(17, "cherries21", 0, 355, 303, 100, 100, 255, 0);}
else {if $gameVariables.value(0024)=== 2{$gameScreen.showPicture(17, "cherries22", 0, 355, 303, 100, 100, 255, 0);}}
else {if $gameVariables.value(0024)=== 3{$gameScreen.showPicture(17, "cherries23", 0, 355, 303, 100, 100, 255, 0);}}}
& *shrugs*
var variableId = 0024;

var value = $gameVariables.value(0024);

if $gameVariables.value(0024)=== 1{$gameScreen.showPicture(17, "cherries21", 0, 355, 303, 100, 100, 255, 0);}

else {if $gameVariables.value(0024)=== 2{$gameScreen.showPicture(17, "cherries22", 0, 355, 303, 100, 100, 255, 0);}}

else {if $gameVariables.value(0024)=== 3{$gameScreen.showPicture(17, "cherries23", 0, 355, 303, 100, 100, 255, 0);}}}
1) in coding, please never use leading zeroes to IDs.
The ID is for example 24, NOT 0024 in one of your examples.

that is because programming languages use leading zeroes to determine the numerical base.
You might have seen 0x or for example 0x1F as a notation for hexadecimal numbers.

and 00 is the indicator for octal numbers, so 0024 is calculated as decimal 20 - you're checking the wrong variable as a result.

2) you should place spaces between different code sections
especially in front of a {

3) as I assumed, you're doing this much too complex.
but since nowhere in your text you describe the game mechanic itself, only what the player is supposed to get, I can only give limited advice here.

But the biggest part of the advice would be to compartimentalize.
If a certain switch is supposed to be checked with another switch, then you should check for that result at both events that are the switches, not hours later at the end.

And you already have been given a much better code for your list of if-codes above:
Try this?

var variableId = 123; // <- edit this var value = $gameVariables.value(variableId); var picName = "cherries2" + value; $gameScreen.showPicture(17, picName, 0, 355, 303, 100, 100, 255, 0);

("cherries2" + value just sticks the number to the end of cherries2. That's how adding text works in JavaScript.)
That code (please check the original above, the quote messed up the format) does EXACTLY the same as

Code:
if $gameVariables.value(0024)=== 1{$gameScreen.showPicture(17, "cherries21", 0, 355, 303, 100, 100, 255, 0);}
else {if $gameVariables.value(0024)=== 2{$gameScreen.showPicture(17, "cherries22", 0, 355, 303, 100, 100, 255, 0);}}
else {if $gameVariables.value(0024)=== 3{$gameScreen.showPicture(17, "cherries23", 0, 355, 303, 100, 100, 255, 0);}}}

You need to construct the string, then all those show picture commands will be combined into a single show picture that gives different pictures without any if command.
Also, you're missing the brackets: if (condition), not if condition.

If you are going to use a long chain of ifs, I'd suggest doing that with event commands rather than a script call. Otherwise, like Andar said, you could try my suggestion. If you're using variable ID 24, it'd be:

var variableId = 24; var value = $gameVariables.value(variableId); var picName = "cherries2" + value; $gameScreen.showPicture(17, picName, 0, 355, 303, 100, 100, 255, 0);

Original thread: https://forums.rpgmakerweb.com/threads/help-with-super-simple-conditional-variable-show-picture-script.148223/