Help a Girl Out! - Making Toggleable Common Events

Hello.
Leave it to me to get super ambitious and want to do something cool with an already cool tool.
Hi.
So I'm working on a game right now--gods know if I'll ever finish it-- but I have just a teensy problem.
I want to create a game mechanic (don't know if that's the right word for it) that when the player presses a certain button, the following happens, functionally speaking:
  1. A common event is called.
  2. In this common event, there are visual changes and sound cues to indicate that this state (henceforth referred to as a "Dream State"--working name) has been activated. In this state, the screen is tinted, there are weather effects, certain objects appear, and the BGM changes.
  3. If the player hits the button again, all of the changes (tinted screen, weather effects, BGM) are reverted to the default state.
How can I make this function into something that can be toggled?
Moderator note: Please give your topics a meaningful title, one which gives an indication of the type of query you have. Queries such as "Help plz!" or "I have a problem" or "Newcomer, & I'm stuck" does not provide enough information. It's quite possible that people will just skip by it in the New Posts/New Threads thinking that's what it is. It also means that if anyone in the future has the same sort of query, they will be unable to find this and (hopefully) the solution.
Moderator note: Please give your topics a meaningful title, one which gives an indication of the type of query you have. Queries such as "Help plz!" or "I have a problem" or "Newcomer, & I'm stuck" does not provide enough information. It's quite possible that people will just skip by it in the New Posts/New Threads thinking that's what it is. It also means that if anyone in the future has the same sort of query, they will be unable to find this and (hopefully) the solution.

Hello,
Thanks for letting me know.
Is it possible to change the title?
You need two switches. One to enable the monitoring, which should be turned whenever you want the player to be able to do this (so it may be turned on right at the start of your game, and remain on for the whole game), and another which will be the toggle.

You need a common event set to parallel process and conditioned by the first switch. In that event, you will have commands like this:
Code:
If <special button> is Pressed
  If Switch [Dream State] is OFF
    ... start weather, add screen tint
    Control Switches [Dream State] ON
  Else
    ... stop weather, remove screen tint
    Control Switches [Dream State] OFF
  End
End
Wait 1 Frame

The events that you want to appear will need to be conditioned by the Dream State switch. And your weather might need to take into account whether you're indoors or outdoors or underground.
What @Shaz explained, but i made an Edit, else the unTint Screen Command will be executed again and again which will draw much Game Performance.
Also i removed the 1 Frame Wait, those are not needed in parallel Event or parallel common event in this case. Wait only causes to sometimes not detect the press of the special button. And button presses need to be checked every frame, because at every frame the press could happen.
And i added a Button release check in form of a Loop at the end of the initial code.
As long the button is being pressed, the loop will continue and nothing happens, when you release the button, the Loop Ends.
Code:
If <special button> is Pressed
  If Switch [Dream State] is OFF
    ... start weather, add screen tint
    Control Switches [Dream State] ON
  Else
    ... stop weather, remove screen tint
    Control Switches [Dream State] OFF
  End
   Loop
   Is Special Button Pressed?
    If yes - Wait 1 Frame
    else - Break Loop
    repeat above
    End
End
I Edited the Codeblock and removed an unnecesarry condition.
Hello,
Thanks for letting me know.
Is it possible to change the title?
Yes. Click on Thread Tools -> Edit Thread and you can change the title.
Oh oh i was so tired, @Shaz codeblock works perfectly fine in this constelation.
I missread was still to asleep and mistook it for a slightly different button press case...
and iam stupid the else case of a switch being off is it being on^^ and i inserted an extra Condition for it, i feel stupid right now.
Sorry for the confusion i brought into this. But the 1 Frame Wait i would still delete in Shaz solution =). Also i Edited my above Codeblock.
The wait is there to reduce lagging caused by a constantly-running parallel process event.
Firstly, hello! Thank you all for the feedback! I really appreciate it!

Since I posted this, I came across Yanfly's Button Common Events plugin that expands the capabilities of keyboard button inputs past the default button scheme. With this, I've mapped the common event to be called with the "D" button. Is this going to cause an issue for the coding?

So I've gotten the effect to activate, but it automatically cancels out. Strangely, the "Dream State" Switch remains on, I think? I think I'm doing something wrong. Please also forgive my slowness as I haven't messed with RPG Maker's coding system in a while, but I've translated @Shaz 's codeblock the best I could.

5a17b1dc8dfad3843672f10cdceaf653.png
It's probably processing the event several times because the key is being held down. @Bex alluded to this. After turning the switch off, add a Wait 60 Frames. Do the same after turning the switch on. This means the event will not trigger again for at least a second. This is in addition to the Wait 1 Frame right at the end. So you will have 3 Wait statements in all.

What happens if dreamstate is on, and you've got the flash/tint/weather, and then Logan leaves the party and the player presses the button again? Nothing would happen. Is that what you intend?

Be careful using switch 1 - if you add any plugins, you'll need to make sure they don't use the same switch - #1 is usually the default used by plugins, so if you have any, you'll need to change them to use a different switch (and give the switch a name so you don't accidentally use it for something else).
It's probably processing the event several times because the key is being held down. @Bex alluded to this. After turning the switch off, add a Wait 60 Frames. Do the same after turning the switch on. This means the event will not trigger again for at least a second. This is in addition to the Wait 1 Frame right at the end. So you will have 3 Wait statements in all.

What happens if dreamstate is on, and you've got the flash/tint/weather, and then Logan leaves the party and the player presses the button again? Nothing would happen. Is that what you intend?

Be careful using switch 1 - if you add any plugins, you'll need to make sure they don't use the same switch - #1 is usually the default used by plugins, so if you have any, you'll need to change them to use a different switch (and give the switch a name so you don't accidentally use it for something else).

Heya, thank you to both you and @Bex--it all worked out! ;A;
I mean for this state to only work if Logan is in the party--is there a way I can ensure this is the case?
Oh wait a second - are you using the same switch for the trigger AND the checks? No, don't do that - use two different switches (I did say you'd need two switches). One switch will control when the checks are active, and the other will control whether dreamstate is on or off. So change the switch in the event commands and use a different one. Everything else will stay the same.

So Logan can leave the party after joining? And come back and leave again? If that's the case, and you want dreamstate to be off when Logan is not in the party, create another common event, this time with NO trigger, and add the following commands:

Code:
If Dreamstate is ON
  Tint screen (0, 0, 0, 0) 30 frames
  Set Weather Effect None 1 frame
  Control Switches Dreamstate = OFF
End

and in any event where Logan leaves the party, do a Common Event call to call this common event.

So, when Logan is in the party, pressing the button will turn dreamstate on and off alternately, and when Logan leaves the party, if dreamstate is on, it will be turned off.
You can always add a "button to command events" plugin to assign a key to your switchable effect and forget about parallel processing which would reduce any lag problems to 0.
@BK-tdm thank you, I actually used yanfly's button to command events plugin, that's a solid suggestion. <3
@Shaz Thank you! I'm going to test and see if that works and let you know if anything changes. :3 <3

Original thread: https://forums.rpgmakerweb.com/threads/help-a-girl-out-making-toggleable-common-events.113757/