Question about Common Events and Parallel Processes.

I'm using Iarva's text sound plugin to make it so there's sounds whenever text is typed, however, I want to give players the option to turn this off.

I've done this via the options menu. I'm using another plugin called DreamX options, which lets me add a Switch to the options menu that players can toggle.

So, what I do is I have a switch called Disable Text Sounds. This then runs a common event as seen here:

upload_2019-2-6_5-54-6.png


As you can see, it just turns the text sound volume to either 50 or 0.

So, it all works. The question I have is about Paralell processes. I honestly don't understand much about them other than you don't want too many of these running at once and that they're like an Update function in Unity or other languages. With the common event, I did try and set the trigger to Autorun at the top, but then it would let me change the option, but once I tried to exit back to the game, it would freeze the game. I assume this is because nothing was telling the common event to stop running. I tried adding Exit Event Process commands in that common event, but it didn't do anything, and there's no way for me to use a Self Switch because Common Events don't seem to have those.

So, with this parallel process that does work, is it actually still running in the background? Do I need to tell it to stop checking somehow?


Thanks.
Autorun is like Paralell but Its mostly used for Cutscenes, the Player cant move with buttin input while its running.
Also only 1 Autorun Event is executed, i read that 2 at the same time dont work.

Your code most likely dont work, the condition for that page to run is the same condition used in your code for the case that the switch is Off, but when the Page condition gets turned off, than the code will not run and therfor the code withthe condition if switch is OFF, will never ever be executed.

Paralell means, when the Eventpage is active (Condition switch ON), than it iterates through the Eventcommands/Scriptcommands, one by one line by line over and over again (Around every 1Frame or in Events around every 4Frames, it depends) .
60 Frames = 1 Second.
But yes most Times they run just one Time and are deactivated afterwards, until they are needed again.
Some are running the entire Game.
As long as the Trigger condition remains on, it'll continue to run. You turn the Switch off to make it stop running.
Autorun is like Paralell but Its mostly used for Cutscenes, the Player cant move with buttin input while its running.
Also only 1 Autorun Event is executed, i read that 2 at the same time dont work.

Your code most likely dont work, the condition for that page to run is the same condition used in your code for the case that the switch is Off, but when the Page condition gets turned off, than the code will not run and therfor the code withthe condition if switch is OFF, will never ever be executed.

Paralell means, when the Eventpage is active (Condition switch ON), than it iterates through the Eventcommands/Scriptcommands, one by one line by line over and over again (Around every 1Frame or in Events around every 4Frames, it depends) .
60 Frames = 1 Second.
But yes most Times they run just one Time and are deactivated afterwards, until they are needed again.
Some are running the entire Game.

Well, this code does work exactly how I want it to. I'm just more asking whether or not that Common Event is always going to be running once a player changes that option in the menu or if it will turn itself off or not.
In my Opinion your code will not work properly, i tryed to explain in the previous post, my english isnt the best.
But i cant see if the page condition switch16 is also used for the eventcommand conditional branch. Could you tell us that.
Than we know if the code in your event can run and give further tips to improove it.
I think what @Bex is saying is that the condition for your common event is that switch 16 "Disable Text Sound" is on. This means you're common event will continue to run so long as said switch is on. If you later decided to turn this switch off, your common event would stop executing, which in theory means that your first conditional branch wouldn't occur and your text sounds would not be re-enabled.

Long story short, this will work to disable sound, but shouldn't work to re-enable sound.

As I said earlier this will keep executing (I believe at a rate of 60 times per second, don't quote me on that), until your switch is turned off. I think a better way of handling this would be to use Yanfly's Utility Common Events plugin and set the common event to run on closing the menu.

http://yanfly.moe/2017/04/21/yep-133-utility-common-events-rpg-maker-mv/

Alternatively, have your button in the menu turn on a second switch, have that as the trigger for your common event and then at the end of the event turn the second switch off - this will mean the event only executes once after the sound is disabled/enabled.

Spoiler
upload_2019-2-5_20-15-44.png
Use two switches - one to track whether the text sound should be on or off, and one to trigger the common event. Make your options menu turn on the second switch and use that as a condition to run the common event (the switch at the top, not in the event commands). Then at the end of the event commands, turn that switch off. That means the common event will only loop once, then turn itself off until the player changes the option again.

So it will look something like this:

Code:
Name: Disable Text Sounds   Trigger: Parallel   Switch: 017 - Toggle Text Sounds (this switch is turned on in the options)

If Disable Text Sounds (switch 16) is ON
  Control Switches 16 - Disable Text Sounds = OFF
  Script: IAVRA.TEXTSOUND.setOptions({volume:50});
Else
  Control Switches 16 - Disable Text Sounds = ON
  Script: IAVRA.TEXTSOUND.setOptions({volume:0});
End

Control Switches 17: Toggle Text Sounds = OFF
Use two switches - one to track whether the text sound should be on or off, and one to trigger the common event. Make your options menu turn on the second switch and use that as a condition to run the common event (the switch at the top, not in the event commands). Then at the end of the event commands, turn that switch off. That means the common event will only loop once, then turn itself off until the player changes the option again.

So it will look something like this:

Code:
Name: Disable Text Sounds   Trigger: Parallel   Switch: 017 - Toggle Text Sounds (this switch is turned on in the options)

If Disable Text Sounds (switch 16) is ON
  Control Switches 16 - Disable Text Sounds = OFF
  Script: IAVRA.TEXTSOUND.setOptions({volume:50});
Else
  Control Switches 16 - Disable Text Sounds = ON
  Script: IAVRA.TEXTSOUND.setOptions({volume:0});
End

Control Switches 17: Toggle Text Sounds = OFF

Okay, this works. as well. With this way, it's not a process that's continuing to run after the player changes it?

This is sort of a follow up question, but I also have an option to turn auto punctuation on or off. That plugin just checks for a switch so I didn't need to do what you've explained like with the Text Sounds option.

But, that switch is starting turned off and I'd like it turned on. Would you just enable it at the start menu, or splash screen or when a player starts a new game or something?
Use two switches - one to track whether the text sound should be on or off, and one to trigger the common event. Make your options menu turn on the second switch and use that as a condition to run the common event (the switch at the top, not in the event commands). Then at the end of the event commands, turn that switch off. That means the common event will only loop once, then turn itself off until the player changes the option again.

So it will look something like this:

Code:
Name: Disable Text Sounds   Trigger: Parallel   Switch: 017 - Toggle Text Sounds (this switch is turned on in the options)

If Disable Text Sounds (switch 16) is ON
  Control Switches 16 - Disable Text Sounds = OFF
  Script: IAVRA.TEXTSOUND.setOptions({volume:50});
Else
  Control Switches 16 - Disable Text Sounds = ON
  Script: IAVRA.TEXTSOUND.setOptions({volume:0});
End

Control Switches 17: Toggle Text Sounds = OFF

One other issue with this is that when I change the option in the menu, while it will disable the sound, no matter what, once I go back to the menu, the option is always set to off. It doesn't reflect what it's actually set to for some reason.

EDIT: if I turn off that final line Control Switches 17: Toggle Text Sounds = OFF, then it does stay off or on correctly.

Also, for some reason, if I load a saved game, it doesn't remember what the options were set to. Same with going from the main menu.
Yes, but if you remove that final line where it turns the switch off, your parallel process is going to keep running. This is bad design, and you should seek another approach if you can't that common event to only run when it needs to.

The other thing is an issue with the script itself, and you should post in the script support topic for help. That has nothing to do with your common event.
Sure in a big Game its better to Event/Code performance Effective and use stuff only when needed.
But for casuals like me this can be a science for itself. So maybe its not bad to have something always run on paralell.
And in case he got to 10 Mechanics in the end all running in an extra Paralell Event, than yes we could try and help him put as many of those into one paralell event, and making sure it runs flawlessly (for which some background knowledge/expirience is needed).

So have a Common Event with Paralell (NOT Autorun), Turn the Condition Switch for it to ON at the beginning of the Game.
Code Idea(Some Copy Paste from @Shaz solution:
We need 2 more Switches.
SwitchX is the Switch shown in your Menu, which you toggle On or Off there.
SwitchY is used so the Commands are only executed once after each switch change, processing only the conditions all the Time is using much less performance reserves (about which we should not worry at the moment)

If SwitchX is On (With Else Case)
Yes: If SwitchY is Off (No Else Case)
-Yes: Turn Switch Y ON and do your Soundchange
-end
else If SwitchY is On (No Else Case)
-YES: Turn SwitchY Off and change your Sound again.
-end
end
Wait 20 Frames

The Paralell Event will continue to repeat this codeblock. This code is not needed to be updated every frame (60Frames = 1 Second), so we insert a Wait Command at the End.
Wait: 20Frames for example. (3Times per second should be responsive enough in case you close the Menu after a Sound Change)

Thisway when you change the Menu Switch for Sound the moment you reenter the Map the sound will change, but the command will be executed only one time when needed, the paralell event continues to run through the entire game.

If this explanation is way to much chinese, please let me know, its not always easy to find the correct words.

Original thread: https://forums.rpgmakerweb.com/threads/question-about-common-events-and-parallel-processes.105301/