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

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.
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.
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
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.
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.
$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
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 "=="
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.
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.
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.
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.
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!
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.

Original thread: https://forums.rpgmakerweb.com/threads/using-a-variable-value-to-refer-to-a-switch-id-in-a-conditional-script-call.138999/