"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,293
Reaction score
1,790
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,801
Reaction score
1,640
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
965
Reaction score
470
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,531
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,801
Reaction score
1,640
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
44,169
Reaction score
15,542
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,801
Reaction score
1,640
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
965
Reaction score
470
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 Profile Posts

Nightmare... Dreamt I posted a GFX resource post. With a work in progress glove icon that tinted to different colors. In the wrong forum. And I was in such a panic. I saw people writing posts in response, those "..." you see in discord and such. So I frantically tried to report my post as wrong forum, editing to say it's the wrong forum and that I "accidentally" posted it too early... Very odd dream to be honest...
The youngest photo of you is also the oldest photo of you.
People need to stop submitting their game to every single game jam without even reading the jam rules (╯°□°)╯︵ ┻━┻
Mom tested positive for COVID thanks to a single stupid coworker of hers not taking sh*t serious.
I'll prolly won't be on here for a while as we deal with this.
So before I inevitably start a new project to reorganize myself (I will make sure to save important info dw), I will make an external list of what I want in the final database.

Forum statistics

Threads
117,204
Messages
1,105,438
Members
153,342
Latest member
pixelpuff
Top