"Switch operation" - Control switch based on a variable

Luth

Veteran
Veteran
Joined
Apr 29, 2014
Messages
148
Reaction score
69
First Language
French
Primarily Uses
RMMZ
Hi again :)

This time I try to reproduce the "Switch operation" event command from RM2K3.

screen.png

This allows to control a switch (Turn OFF/ON), which number is saved in a variable.

For instance, if my variable is = 2, then the Switch number 2 will be turned ON/OFF.

Is it possible to reproduce with MZ ?

Thanks :)
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
2,226
Reaction score
1,725
First Language
Portuguese - Br
Primarily Uses
RMMZ
Hi there!
Nice suggestion! I will add that into Eli Switches!

NOTE: I just can't believe that RM2K3 have a toggle option and MV/MZ not o_O
 

Luth

Veteran
Veteran
Joined
Apr 29, 2014
Messages
148
Reaction score
69
First Language
French
Primarily Uses
RMMZ
Hi there!
Nice suggestion! I will add that into Eli Switches!

NOTE: I just can't believe that RM2K3 have a toggle option and MV/MZ not o_O

Hello, thanks for the answer :)
I can't believe it either :mad: I think it's not the only thing that disappeared though :(

(I'll give a look at your plugin when it's done :) )
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,272
Reaction score
1,228
First Language
English
Primarily Uses
RMMV
That is a weird omission. However, it's pretty easily reproduced by a script call:
Code:
$gameSwitches.setValue(X, $gameSwitches.value(X) ? false : true);
where both X's are the ID of the switch.
 

Mr_Petue

Villager
Member
Joined
Sep 24, 2021
Messages
5
Reaction score
1
First Language
german
Primarily Uses
RMMZ
hello,
you are not alone,
i was so frustrated, as i saw, that the rmmz doesnt allow you to connect items with common events ( like for example in the xp version).
had to make a complete new menu (for what i wished), which is still not complete. sorry i dont wanted to spam. but i am still angry about it.
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
894
Reaction score
443
First Language
PT-BR
Primarily Uses
RM2k3
That is a weird omission. However, it's pretty easily reproduced by a script call:
Code:
$gameSwitches.setValue(X, $gameSwitches.value(X) ? false : true);
where both X's are the ID of the switch.
I understood differently, in this case the X would be the variable as in the image.
Something like:
JavaScript:
$gameSwitches.setValue($gameVariables.value(X), true);

Toggle between ON and OFF:
JavaScript:
$gameSwitches.setValue(X, !$gameSwitches.value(X));

Or did I get it wrong?
 

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
525
Reaction score
1,528
First Language
Indonesia
Primarily Uses
RMMV
Isn't the request to toggle a switch ID referenced from a value of a certain variable?
Then shouldn't it be like this?

Code:
var v_id = $gameVariables.value(X);
$gameSwitches.setValue(v_id, !$gameSwitches.value(v_id));

If Variable X value is 2, then Switch 2 will be toggled ON/OFF.
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,272
Reaction score
1,228
First Language
English
Primarily Uses
RMMV
@Kuro DCupu That's true - I was focusing on the toggle aspect which doesn't natively exist in MV/Z the way it does in that screenshot.

Replacing the X in any of the code posted above with the script call for a variable's value was just a simple Google away :wink: But you're absolutely right.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
43,742
Reaction score
15,312
First Language
English
Primarily Uses
RMMV

@Mr_Petue please do not make posts that have nothing to do with the rest of the thread



Also don't harass other members to give you explanations of why they added a negative reaction to your post. You posted in the wrong place, distracting the conversation that was in progress. That is why they did that. They are not obligated to explain their reasons to you.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,272
Reaction score
1,228
First Language
English
Primarily Uses
RMMV
I was referring to this option:
Your post confused me because the line of code you gave that would toggle the switch didn't reference the variable...just like mine did not. So they did the same thing.

My brain glossed over the whole variable part of it, as Kuro pointed out :stickytongue:
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
894
Reaction score
443
First Language
PT-BR
Primarily Uses
RM2k3
Got it, sorry, it was just an add-on to a more practical way of checking true/false.
 

Luth

Veteran
Veteran
Joined
Apr 29, 2014
Messages
148
Reaction score
69
First Language
French
Primarily Uses
RMMZ
Isn't the request to toggle a switch ID referenced from a value of a certain variable?
Then shouldn't it be like this?

Code:
var v_id = $gameVariables.value(X);
$gameSwitches.setValue(v_id, !$gameSwitches.value(v_id));

If Variable X value is 2, then Switch 2 will be toggled ON/OFF.

This works like a charm ! Thanks a lot ! :kiss:
 

Mr_Petue

Villager
Member
Joined
Sep 24, 2021
Messages
5
Reaction score
1
First Language
german
Primarily Uses
RMMZ
[mod]@Mr_Petue please do not make posts that have nothing to do with the rest of the thread[/mod]

Also don't harass other members to give you explanations of why they added a negative reaction to your post. You posted in the wrong place, distracting the conversation that was in progress. That is why they did that. They are not obligated to explain their reasons to you.
I speak politely to whoever I want. You react way to hard!

edit: I dont "harass" other people. You have come into my live and harass me!
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

I'm so annoyed with myself...I can't get this code to work so it looks like I'm going the plugin route for a problem I should be able to do myself :kaolivid:Great. Now I get to murder save file compatibility. Again.
Can't believe my code from four years ago is still working! Did some expansions, and...
1635194553179.png
In related news, I may have an update for my old Extra status window plugin ready. That is, once I manage to sit down and update the documentation... and the demo project... :kaoswt:
How does one pronounce Godot? I've heard it pronounced a couple of different ways, and I genuinely don't know the proper way.
March 2020 ...
1635188823939.jpeg
... vs October 2021
You look like you had a rough day...Here, have a Baby Panda!

Forum statistics

Threads
116,077
Messages
1,095,542
Members
151,441
Latest member
guertena_1
Top