How to store a currently playing BGM to variable, play a different one, then restore original?

Hi wonderful RPGM folks! Simple one here, I bet ...

... I have a common event menu that a player can call up at any time. While the player is in this menu, I want to play a specific BGM. Then, when the player exits this common event menu, it goes back to whatever the BGM was in the area where they called the common event menu.

I'm trying to figure out the best way to do this. I've asked before about storing BGM volume, as a means of later on restoring the BGM to the level the player had it set at, but I'm realized this is a bit more of a complicated problem (at least for me).

I've been thinking about just fading the BGM down to 0, then playing the new music as a BGS (which works since BGS loops, meaning the player can spend as much time in the menu), then when the player exits the common event menu, ending the BGS and restoring the volume of the BGM, but this is still quite complicated for a noob like me ...

If any experienced folks have a clear and easy way to play different music temporarily during a quick cutscene that can be called at any time, please lend me a hand ... thanks so much!!!

c
This was done using the normal menu called up when you hit the cancel button, but it should be fairly straightforward to work it into the common event for your custom menu.
MenuMusic.png

A few notes to go with this:
» Make sure you have “Parallel Switch” turned on anytime where you’re supposed to get into the menu, and turned off anytime you’re not.
» The whole rigmarole involving the “Cancel Is Pressed” switch prevents the game from trying to change the music for the whole time you hold down the cancel after coming out of the menu.
» The script is so that the game plays the non-menu music from the start. If you want to pick the original music up where it left off, just use Save BGM and Replay BGM instead.
» If you keep holding down the cancel button when you go into the menu, it will kick you back out of the menu and into normal gameplay. I… don’t have a solution to that, admittedly.
I am pretty sure I have seen something about this a few times. I don't know if these will help you, but here are a couple of links to look at if the solution provided by @AssumedPseudonym doesn't do what you want. I haven't personally played around with this yet so I don't know for sure.


@AssumedPseudonym and @ZombieKidzRule thank you!

I'm going to try pseudonym's "rigmarole" and see if that fits the bill ... truly appreciate the time and care put into providing this solution, it's not something I could have come up with myself. Will report back shortly!
Solved! I actually got it to work actually with a simplified version of that solution along with Save BGM and Replay BGM, so literally a combination of both of your answers 🙂

Very cool. Thank you @AssumedPseudonym and @ZombieKidzRule
I’m actually glad you asked this one. I might be using this on my own later projects, if not my current one. Having the menu have its own music reminds me of my introduction to RPGs with the original Final Fantasy.
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/how-to-store-a-currently-playing-bgm-to-variable-play-a-different-one-then-restore-original.155251/