Menu music

How do I make it play music in the menu screen (not the title screen) and then resume the last playing bgm? (Without restarting it)
I was trying to mute the bgm and play bgs for the menu instead, and then unmuting the bgm once the menu closed, but I couldn't figure out how to do any of that.
Oh and I'm using VX Ace.
Moved to: RGSS3 Script Requests
I'm a bit rusty with RGSS3 but I can suggest doing it with Common Events:
My RMVXA being from Steam is in the language of my operating system, which is not English, so I will try to explain it in stages.

Open the database, go to the Common Events tab.
Create a new event, switch to Parallel process.
Select a switch of your choice and name it "Call_Main_Menu".

Inside the event call the event command, go to page 3 in "System Settings" and select the command "Change Menu Access...", use the Disable operation.

Now create a new event command, on page 1 under "Flow Control" select "Conditional Branch...".
Go to page 4 and select the Button option and change it to "B" and uncheck the option "Set handling when conditions do not apply".

At this point it should look like this:
Code:
@>Change Menu Access: Disable
@>Conditional Branch: The B Button is Being Pressed
   @>
 : Branch End
@>

Inside this Conditional Branch... enter a new event command, page 2, "Music and Sounds" select the command "Save BGM".

Now enter "Play BGM...", select the song you want to be the theme from the menu.

Enter a new event command, page 3, "Scene Control" select the "Open Menu Screen" command.

Enter a new event command, page 2, "Music and Sounds" select the command "Replay BGM".

Code:
@>Change Menu Access: Disable
@>Conditional Branch: The B Button is Being Pressed
   @>Save BGM
   @>Play BGM: 'Theme Menu', 100, 100
   @>Open Menu Screen
   @>Replay BGM
   @>
 : Branch End
@>

After the introduction of the game, activate the Switch from the menu, in every cutscene event or long dialogue between characters, deactivate this Switch.
This seemed to work pretty well, thanks.
If you keep the "B" button held when exiting the menu it will open then, you can solve this with one more Switch.
But it's a little more complex.
Ruby:
module R2_Menu_Sound
  SONG = "Theme1"
end

class Scene_Menu < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
    super
    song = RPG::BGM.new(R2_Menu_Sound::SONG, 100, 100)
    song.play
    create_command_window
    create_gold_window
    create_status_window
  end
end

class Scene_Map < Scene_Base
  def call_menu
    Sound.play_ok
    @last_bgm = RPG::BGM.last
    SceneManager.call(Scene_Menu)
    RPG::BGM.stop
    Window_MenuCommand::init_command_position
  end
  alias r2_update_map_scene update_scene
  def update_scene
    r2_update_map_scene
    return if SceneManager.scene_is?(Scene_Menu)
    @last_bgm.play(@last_bgm.pos) if @last_bgm != nil
    @last_bgm = nil
  end
end
This one works, but the only issue is that the map bgm starts back at the beginning when I exit the menu.
Ruby:
module R2_Menu_Sound
  SONG = "Theme1"
end

class Scene_Menu < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
    super
    song = RPG::BGM.new(R2_Menu_Sound::SONG, 100, 100)
    song.play
    create_command_window
    create_gold_window
    create_status_window
  end
end

class Scene_Map < Scene_Base
  def call_menu
    Sound.play_ok
    @last_bgm = RPG::BGM.last
    SceneManager.call(Scene_Menu)
    RPG::BGM.stop
    Window_MenuCommand::init_command_position
  end
  alias r2_update_map_scene update_scene
  def update_scene
    r2_update_map_scene
    return if SceneManager.scene_is?(Scene_Menu)
    @last_bgm.play(@last_bgm.pos) if @last_bgm != nil
    @last_bgm = nil
  end
end
It works on a default system (no other scripts).
What scripts do you have?
Really the music restarts, I auditioned on a new project.

Edit1:
Reading the default scripts, I found this in Game_System from line 110:
Ruby:
 #--------------------------------------------------------------------------
  # * Save BGM
  #--------------------------------------------------------------------------
  def save_bgm
    @saved_bgm = RPG::BGM.last
  end
  #--------------------------------------------------------------------------
  # * Resume BGM
  #--------------------------------------------------------------------------
  def replay_bgm
    @saved_bgm.replay if @saved_bgm
  end

Could it be the case to use the replay command?
Do you mean to use replay instead of .pos ?
I still don't understand why it doesn't work for other people.
Here is a blank project.
Works fine. I start the game, wait for the music to change and then open the menu. navigate a bit, close the menu and when the previous bgm fades back in it's where it left off.

Tested replay, same result
Anyway, I've got this alternative just in case @Spacer789 needs it. I've tested it and the BGM and BGS do restart right where it was interrupted. (The autoplay Map BGM or BGS feature gotta be activated...)

Ruby:
# * KMenuSound ACE
#   Scripter : Kyonides Arkanthes
#   2021-10-01

# This scriptlet will let you resume the BGM or BGS previously played on the
# current map right after exiting the menu scene. Besides the menu also features
# its very own BGM! Please feel free to set the values of KMenuSound module's
# Constants at will.

module KMenuSound
  BGM = "Theme2"
  VOLUME = 70
  PITCH = 100
  extend self
  attr_accessor :bgm_pos, :bgs_pos
  @bgm_pos = 0
  @bgs_pos = 0
end

class Game_Map
  def play_last_bgms
    @map.bgm.play(KMenuSound.bgm_pos) if @map.autoplay_bgm
    @map.bgs.play(KMenuSound.bgs_pos) if @map.autoplay_bgs
  end
end

class Scene_Menu
  include KMenuSound
  alias :kyon_menusnd_scn_menu_start :start
  def start
    kyon_menusnd_scn_menu_start
    bgm = RPG::BGM.new(BGM, VOLUME, PITCH)
    bgm.play
  end
end

class Scene_Map
  alias :kyon_menusnd_scn_map_start2 :post_start
  alias :kyon_menusnd_scn_map_call_menu :call_menu
  def post_start
    kyon_menusnd_scn_map_start2
    $game_map.play_last_bgms
  end

  def call_menu
    KMenuSound.bgm_pos = RPG::BGM.last.pos
    KMenuSound.bgs_pos = RPG::BGS.last.pos
    kyon_menusnd_scn_map_call_menu
  end
end
Do you mean to use replay instead of .pos ?
No, I meant that maybe it was the right method, but I hadn't tested it either.
I don't understand almost anything about RGSS, I read from the comments in the Script, but it was my misinterpretation, so I asked you if it could be.

I included this after memorizing it in the variable, the result was this:
puts @last_bgm.pos

1.png


I tested your project and it worked perfectly.
So I did the test with the event commands in my project and I realized that neither the "Save BGM" and "Replay BGM" events work, it's a problem in the Scripts generated in the non-English version.
I thought that only the comments were different because they were translated.
I'll try to bypass Steam's RmVXA to stay in English.
@kyonides Thanks. I'll keep yours. You have more scripting experience.
I didn't know I could use .pos after the .last

Original thread: https://forums.rpgmakerweb.com/threads/menu-music.140864/