RMMV Using a variable value to refer to a switch ID in a conditional script call

HankB

Veteran
Veteran
Joined
Mar 5, 2021
Messages
86
Reaction score
28
First Language
English
Primarily Uses
RMMV
Hi. I think maybe I'm using the wrong syntax, but I can't figure out what it is.

Let's say the value of variable #303 is 105. Then I want to check if switch #405 is on or off. This is what I'm using:

frmq1.png

Does this look right? Because it's not working, and I can't find any other reason. Thanks.
 

ScorchedGround

Blizzards most disappointed fan (More than ever)
Veteran
Joined
Apr 12, 2020
Messages
632
Reaction score
848
First Language
German
Primarily Uses
RMMV
Not sure if I understand the essence of the question, but
you don't need the brackets in this.

$gameSwitches.value($gameVariables.value(303)) == true

should suffice.
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
1,226
Reaction score
709
First Language
Poland
Primarily Uses
RMMV
Game Switches and Self Switches are boolean types, so they can only take either true or false state.
Besides don't use square brackets...

$gameSwitches.value($gameVariables.value(303)) == true
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,860
Reaction score
970
First Language
English
Primarily Uses
RMMV
You have two problems. First, your original description is confusing - you say the value of #303 is 105, but then you want to check switch #405. Did you mean #105? Or should you be adding something?

Second, you're using brackets instead of parentheses. it needs to be $gameSwitches.value() each time.
 

HankB

Veteran
Veteran
Joined
Mar 5, 2021
Messages
86
Reaction score
28
First Language
English
Primarily Uses
RMMV
you say the value of #303 is 105, but then you want to check switch #405
If you look at the top you'll see that I did add 300 to var 303, making it 405. Per @Soulrender 's
suggestion I changed it to:

$gameSwitches.value($gameVariables.value(303)) == true

and am still getting the same results.
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
1,226
Reaction score
709
First Language
Poland
Primarily Uses
RMMV
$gameSwitches.value(id) can be either true or false so if you wish to set switch true, by value of variable #303 then you do this code:

$gameSwitches.setValue($gameVariables.value(303), true)

Then using conditional branch you use code
$gameSwitches.value($gameVariables.value(303)) == true

but I would use
$gameSwitches.value($gameVariables.value(303)) === true

wich means "check switch id if is EXACLY true
 

ScorchedGround

Blizzards most disappointed fan (More than ever)
Veteran
Joined
Apr 12, 2020
Messages
632
Reaction score
848
First Language
German
Primarily Uses
RMMV
and am still getting the same results.

What is the "same result"? You never spoke of any result.

Here is a trick for bughunting:
After you add 300 to the variable, put in a "show message" with \V[303] to see what the value of the variable actually is at that point.

Also I concur with @Soulrender in using "===" instead of just "=="
 
Last edited:

HankB

Veteran
Veteran
Joined
Mar 5, 2021
Messages
86
Reaction score
28
First Language
English
Primarily Uses
RMMV
After you add 300 to the variable, put in a "show message" with \V[303] to see what the value of the variable actually is.
That's exactly what I've been doing, and it should be false but is showing as true.

but I would use
$gameSwitches.value($gameVariables.value(303)) === true
Wait, is it supposed to be 3 equal signs? I tried it with === instead of ==, getting same results.
 

ScorchedGround

Blizzards most disappointed fan (More than ever)
Veteran
Joined
Apr 12, 2020
Messages
632
Reaction score
848
First Language
German
Primarily Uses
RMMV
That's exactly what I've been doing, and it should be false but is showing as true.

Well that's not exactly what I asked of you.
In your first post you showed us a mockup picture.
And there you increased variable 303 by 300.

I want you to put a "show message" command RIGHT AFTER that, with \V[303] in it.
This should tell you the value of the variable and not "true" or "false".

I just want to make sure that the value is ACTUALLY 405 and not something else.
 

HankB

Veteran
Veteran
Joined
Mar 5, 2021
Messages
86
Reaction score
28
First Language
English
Primarily Uses
RMMV
I want you to put a "show message" command RIGHT AFTER that, with \V[303] in it.
This should tell you the value of the variable and not "true" or "false".

No, I get it, I'm saying that that's exactly what I've been doing (I use that method all the time), and the message is showing 405.
 

ScorchedGround

Blizzards most disappointed fan (More than ever)
Veteran
Joined
Apr 12, 2020
Messages
632
Reaction score
848
First Language
German
Primarily Uses
RMMV
Okay, then I am sorry for misunderstanding.
But that's very strange.

Well then you should check if this event works in general.

Here, I made this quick mockup, to test the event myself:

pic.png

This works fine for me.

The first time I play the event it says "yes" because the variable is 421 and switch 421 is "true"
The second time I play the event it says "no" because the variable is 842 and switch 842 is "false"

So if your variable really has the value you want, then something else is going on with your script.
 

HankB

Veteran
Veteran
Joined
Mar 5, 2021
Messages
86
Reaction score
28
First Language
English
Primarily Uses
RMMV
So if your variable really has the value you want, then something else is going on with your script.
Yeah, I think something else is going, probably a problem with my logic.

I appreciate everyone helping out, thanks!
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,860
Reaction score
970
First Language
English
Primarily Uses
RMMV
And just for your knowledge, in this case, there is no reason for it to matter whether you use == or ===. Switches in MV can only have a true or false value, so == works perfectly fine. The only reason to use === is when there's a possibility for comparing variables of different types and you need it to match exactly (for example, saying "1" === 1 will evaluate to false, but "1" == 1 is true).

This doesn't matter at all in your script because you're using a built-in function that will only return true or false. In fact, you don't even need to compare it to anything, you can simply say if ($gameSwitches.value(X)) and it will proceed correctly if the function returns true.

Ultimately, in this case, there has to be someplace in your game where you're accidentally setting that switch, or not resetting it after use.
 

Latest Threads

Latest Posts

Latest Profile Posts

seems absolutely WILD to me now all the hundreds of hours of work I used to do in 2k(3) over a decade ago with a resolution of 320x240. that seems so insanely TINY now, seemed so normal at the time!
Playing Aroma Indosiar theme song.
Aroma is an Indonesian TV show about cooking. :)
Working on a characteeer! (Why is it so hard to color hair?) ;-;
Silly-Sketches.png
Just finished eventing a couple simple puzzles in RMMV, for my very first game "Sample Quest." Just messing around, throwing things together, and calling it a story XD On a non-RM note, got my hair cut today!
I feel the need to inform everyone on the forums NOT to go with Web Hosting Canada for your hosting needs. It is by far the worst customer service and just overall experience I have ever had with hosting and I am Canadian...

Forum statistics

Threads
115,372
Messages
1,089,347
Members
150,067
Latest member
GutterRat
Top