Toggle Music Switch

First of all, thank you to Galv for providing the music switch script, which is

module BattleManager B_MUSIC_SWITCH = 1 # Turn switch ON to disable battle AND victory music # Battle Background Music def self.play_battle_bgm $game_system.battle_bgm.play if $game_switches[B_MUSIC_SWITCH] == false RPG::BGS.stop end # Victory Background Music def self.play_battle_end_me $game_system.battle_end_me.play if $game_switches[B_MUSIC_SWITCH] == false endendI would just like to know, how can I toggle the B_MUSIC_SWITCH ingame? I would like to know because only during certain parts of the game I want the BGM to continue to play throughout the battle.
Control Switches


That line is just saying what switch you want to use to toggle the music. It is set to 1 by default. If you are using switch 1 for something else, you need to assign a new switch to music toggle (and name it so you don't accidentally use it for another purpose), then change the 1 in the script to the number of the switch you are going to use.


And you would have to change the switch BEFORE going into battle - it only takes effect when the command to play music is executed - if the switch is off when that command runs, the music won't play, and if you then turn it on, it won't suddenly make it play. It's not like turning the volume right down and then up again when you want to hear it.


I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/toggle-music-switch.44897/