JS Condition check the Switch/Variable current value

Status
Not open for further replies.

rechronicle

Mystvaldia
Veteran
Joined
Oct 30, 2013
Messages
137
Reaction score
109
First Language
Bahasa
Primarily Uses
RMMV
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.. :kaodes:
 

Susan

Veteran
Veteran
Joined
Sep 1, 2014
Messages
2,748
Reaction score
8,346
First Language
No idea...
Primarily Uses
RMMV
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.
 
Last edited:

rechronicle

Mystvaldia
Veteran
Joined
Oct 30, 2013
Messages
137
Reaction score
109
First Language
Bahasa
Primarily Uses
RMMV
Whoa nice2, tried it out and works well with the plugin. Thank you!
 

Shigekims

Villager
Member
Joined
Dec 21, 2018
Messages
6
Reaction score
0
First Language
English
Primarily Uses
RMMV
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.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,523
Reaction score
1,415
First Language
English
Primarily Uses
RMMV
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.
 

ryoma1492

Villager
Member
Joined
Nov 11, 2017
Messages
6
Reaction score
1
First Language
English
Primarily Uses
RMMV
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
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,523
Reaction score
1,415
First Language
English
Primarily Uses
RMMV
$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.
 

ryoma1492

Villager
Member
Joined
Nov 11, 2017
Messages
6
Reaction score
1
First Language
English
Primarily Uses
RMMV
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!
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA

I've moved this thread to JavaScript Support. Please be sure to post your threads in the correct forum next time. Thank you.

 

ryoma1492

Villager
Member
Joined
Nov 11, 2017
Messages
6
Reaction score
1
First Language
English
Primarily Uses
RMMV
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);
}
 
Status
Not open for further replies.

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

Latest Threads

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,860
Messages
1,017,040
Members
137,569
Latest member
Shtelsky
Top