Conditional branch - different switches, all the same value

Hey all,

This question is a bit similar to my other topic, but since its a different question i forgot to ask in the other one, i figured ill just make a new topic.

Ok so im wondering if there is a way to shorten this conditional branch script:

$gameSwitches.value(41) === false && $gameSwitches.value(43) === false && $gameSwitches.value(45) === false

into something like this for example:

$gameSwitches.value(41),(43),(45) === false

Im making a check which requires a huge amount of switches to all be false, and using the first method would create a huge pile of long text.

Thanks in advance!
$gameSwitches.value(41),(43),(45) === false is impossible, because $gameSwitches.value is a function with a parameter. So it has this exact shape ($gameSwitches.value (41)) and no different one.
There is no real shortcut here.
PHP:
//alias gameSwitches for less typing
var gs = $gameSwitches;

//Compares each one and returns true if all of them match up with the last false.
gs.value(41) === gs.value(43) === gs.value(45) === false
That should make it easier on you.
PHP:
//alias gameSwitches for less typing
var gs = $gameSwitches;

//Compares each one and returns true if all of them match up with the last false.
gs.value(41) === gs.value(43) === gs.value(45) === false
That should make it easier on you.
hmmm its strange but rpg maker MV says gs is not defined
Unfortunate, but at least you can still drop your && in your statements for everything.

Simply replace gs with $gameSwitches
Unfortunate, but at least you can still drop your && in your statements for everything.

Simply replace gs with $gameSwitches
ye it still saves quite some space, thanks! Did you just figure gs would work, but werent sure? or did i do something wrong?
It was more an assumption; I'm surprised it didn't work. Lol
It was more an assumption; I'm surprised it didn't work. Lol
haha, quite a shame it doesnt. Id love me some shortcuts.
actually today i actually only came around to really testing the
"$gameSwitches.value(41) === $gameSwitches.value(43) === $gameSwitches.value(45) === false" method.
I just assumed it would work because i didnt get an error. But apparently that doesnt either. I guess ill just have to stick to writing all the scripts in a notepad or something and then copying it to rpg maker.

Altough... Anyone have any other smart ideas to work with long scripts in conditional branch?
What error did you get?
What error did you get?
i didnt get an error. But it just doesnt act the same way a ''$gameSwitches.value(41) === false && $gameSwitches.value(43) === false && $gameSwitches.value(45) === false'' script would act. Im not sure what ''$gameSwitches.value(41) === $gameSwitches.value(43) === $gameSwitches.value(45) === false'' is doing
Ahhh okay by the way, are you doing this in a script call or for a plugin?
Ahhh okay by the way, are you doing this in a script call or for a plugin?
im using this in a script call for a conditional branch
Well, a bit late but you could try this to see if it works:

Just before the conditional branch, use this script call:

Code:
var switches = [41, 43, 45]; // Fill with switches you want checked.
var checkFor = false; // Whether to check if all switches are true or if all switches are false.

var gs = $gameSwitches._data;
this._switchesCheck = true;

for (var i = switches[0];;) {
    if (checkFor) {
    if (!gs[i]) {
        this._switchesCheck = false;
        break;
    }
    } else {
    if (gs[i]) {
        this._switchesCheck = false;
        break;
    }
    }
    var index = switches.indexOf(i);
    if (index === switches.length - 1) break;
    i = switches[index+1];
}

You just need to change the first two lines to fit the situation. The rest can stay as is.

Then in the conditional branch, just use the script condition:

Code:
this._switchesCheck
Well, a bit late but you could try this to see if it works:

Just before the conditional branch, use this script call:

Code:
var switches = [41, 43, 45]; // Fill with switches you want checked.
var checkFor = false; // Whether to check if all switches are true or if all switches are false.

var gs = $gameSwitches._data;
this._switchesCheck = true;

for (var i = switches[0];;) {
    if (checkFor) {
    if (!gs[i]) {
        this._switchesCheck = false;
        break;
    }
    } else {
    if (gs[i]) {
        this._switchesCheck = false;
        break;
    }
    }
    var index = switches.indexOf(i);
    if (index === switches.length - 1) break;
    i = switches[index+1];
}

You just need to change the first two lines to fit the situation. The rest can stay as is.

Then in the conditional branch, just use the script condition:

Code:
this._switchesCheck
hmmm i get an error when i use this:
◆Script:var switches = [5, 6, 7, 8, 9]; // Fill with switches you want checked.
:Script:var checkFor = false; // Whether to check if all switches are true or if all switches are false.
:Script:
:Script:var gs = $gameSwitches._data;
:Script:this._switchesCheck = true;
:Script:
:Script:for (var i = switches[0];😉 {
:Script: if (checkFor) {
:Script: if (!gs) {
:Script: this._switchesCheck = false;
:Script: break;
:Script: }
◆If:Script:this._switchesCheck
◆Play SE:Bell3 (10, 150, 0)
◆
:End

I get the error: SyntaxError: Unexpected end of input.

But honestly, ive resorted to just writing down the whole scriptcall with all the switches on a notepad, where its easier to check for spelling mistakes. And then copying the whole thing over to script box in rpg maker. I appreciate your time, but i dont want you to go through all this effort for something that ive made peace with. So thanks 🙂

Original thread: https://forums.rpgmakerweb.com/threads/conditional-branch-different-switches-all-the-same-value.81386/