JS Condition check the Switch/Variable current value

Hello,
I am having trouble with SRD_HUD Maker. I have tried to go to script call list, but it seems different.
This field (see attachment) requires a condition to fill in the blank. How to write "switch x is true/false" in JS?
1503832756701.jpg

I might also need to check "variable x value = n". Having trouble figuring this out for quite some time.
Is there any list of the Conditions out there? (Maybe similar to Script Call list)

Please help.. 😩
The JS script calls are as follows:
Code:
//To check a switch
$gameSwitches.value[x] == true

//To set a switch
$gameSwitches.setValue[x] == true

//To check a variable
$gameVariables.value(x) == n
Replace "x" with the switches or variables ID.
Replace "n" with your variables value.
For switches: $gameSwitches.value(x) == true
For variables: $gameVariables.value(x) == n
Whoa nice2, tried it out and works well with the plugin. Thank you!
For those working with switches in a Javascript plugin, it would instead be

Code:
//To check a switch
if ($gameSwitches.value(x) == true){ }
//or simply:
if ($gameSwitches.value(x)){ }

//To set a switch to true
$gameSwitches.setValue(x,true)

Where x is the switch number in RPG Maker MV.
Just a quick note about switches:

Code:
if ($gameSwitches.value(x) == true)

is the same as

Code:
if ($gameSwitches.value(x))

Conditional statements are meant to evaluate to either true or false, but since switch values are either true or false already, there's no reason to compare them to true or false. If that makes sense.
I just found this... and realized that what you are describing i am already trying...

Can this code be used in a plugin's "scene" and still affect the game-at-large?

I can't get, in my case, switch 20 to set to true (or false) ... and when i Use the console, i can put the same command and it works

example :


$gameSwitches.setValue(20, true); won't work in my script (everything else functions beautifully and fully, and no error is provided in the console log)

but

the same command in the console command section will set switch 20 to true, like i'd expect
$gameSwitches should be accessible anywhere because it's global. Try putting a console.log("stuff here") directly above or below your $gameSwitches.setvalue() to make sure it's even being reached in the first place. If nothing shows up in the console after that, then you found your problem.
I'll try that to make sure... but what i meant when i said that everything else is performing beautifully is that the other pieces in the same scope (immediately above and below) are being performed without error.


however, I would be stupid to not try and see if this shows off something i didn't expect... I'll update this when i have tried, thanks So MUCH for helping!

I've moved this thread to JavaScript Support. Thank you.

Thanks .... i DID put your thing in there...

and, it did get there...

I chose top make my "console.log" useful, so i dumped the variable i was attempting to set into the console, along with some text...

that's when i realized i had a misstep somewhere in "what switch i was using"..... which feels really dumb...

without your help in making me rethink what i was doing, i would have just beat my head against a wall, so THANKS


This is my code snippet that showed me that i had the wrong number... you were right, it was working the whole time


if (wincondition) {
this._log.setText(victoryText[0], victoryText[1]);
console.log(pnum("Win Switch Number"));
$gameSwitches.setValue(pnum("Win Switch Number"), true);
console.log("This is after Win Switch Number");
justWon=true;
if (actorChoiceId) {
$gameActors._data[actorChoiceId].gainExp(100);
}
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/js-condition-check-the-switch-variable-current-value.83259/