Posts: 28
	Threads: 8
	Joined: Sep 2012
	
	
 
	
	
		Hi,
I've been experimenting with a menu option to reduce / increase the background music volume in my game.
The code works but the changes only take effect when a new piece of background music plays (it does not effect the current background music playing).
Does any one know the script command to stop and start background music?
I want to have the msuic stop and start when the levels are adjusted so they take effect immediatley.
Many Thanks!
	
	
	
	
	
 
 
	
	
	
		
	Posts: 1,033
	Threads: 36
	Joined: Oct 2011
	
	
 
	
	
		why would you need a script for this? just re-adjust the volume and pitch worh the "play BGM" event command.
	
	
	
	
	
 
 
	
	
	
		
	Posts: 28
	Threads: 8
	Joined: Sep 2012
	
	
 
	
	
		I've created a menu screen which has a volume slider to increase and decrease the background music volume here is the script:
 
Code:
#--------------------------------------------------------------------------
  def update_se_regulation
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @se_regulation = false
      @command_window.active = true
      return
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      @se_regulation = false
      @command_window.active = true
      return
    end
    if Input.repeat?(Input::RIGHT) and $game_system.se_volume < 100
      $game_system.se_play($data_system.cursor_se)
      $game_system.se_volume += 1
      @option_window.refresh
    end
    if Input.repeat?(Input::LEFT) and $game_system.se_volume > 0
      $game_system.se_play($data_system.cursor_se)
      $game_system.se_volume -= 1
      @option_window.refresh
    end
  end
  #--------------------------------------------------------------------------
 The menu is supposed to allow the user to decrease or increase the background music - the problem is it only takes affect when the background music stops and starts again - not if it is currently playing, which is why I need to try and incorporate a stop and start value into this.
	
 
 
	
	
	
		
	Posts: 1,033
	Threads: 36
	Joined: Oct 2011
	
	
 
	
	
		do you have a demo? im curious to see how this is different from using events.
	
	
	
	
	
 
 
	
	
	
		
	Posts: 28
	Threads: 8
	Joined: Sep 2012
	
	
 
	
	
		To speed things up here is a link to another version of the same game I'm working on already uploaded - it has the same script for you to look at.
http://www.mediafire.com/?vwa1yy2us7uvu5y 
The script is under the OPZIONI section - to see it in action start the game from any continue - press X to go to the menu and go to "Options" - the sound selection is in there.
It works but just needs an interupt to stop the background music from playing and then to start it again so it is at the new volume - which I can't seem to do!
	
 
 
	
	
	
		
	Posts: 422
	Threads: 23
	Joined: Aug 2011
	
	
 
	
	
		I can see why you'd want that feature; default RPG Maker XP music is LOUD. 
Try:
$game_system.bgs_memorize
$game_system.bgs_restore
EDIT: Nope, sorry. it's:
      $game_system.bgm_memorize
      $game_system.bgm_stop
      $game_system.bgm_restore 
I added it to both Input.trigger?s in def update_me_regulation and it worked.
also, the option menu was missing text. Is that because I didn't install fonts?
	
	
	
	
	
 
 
	
	
	
		
	Posts: 974
	Threads: 139
	Joined: May 2009
	
	
 
	
	
		You can decrease the volume of the track already playing too, there is no need to stop and re-start it. Besides that, if you use $game_system.<sound>_memorize or restore, it'll override whatever you've memorized via events.
Here's a sample of how you could do it...
Code:
bgm_flag = $game_system.playing_bgm.is_a?(RPG::AudioFile)
bgs_flag = $game_system.playing_bgs.is_a?(RPG::AudioFile)
$game_system.playing_bgm.volume = new_bgm_volume if bgm_flag
$game_system.playing_bgs.volume = new_bgs_volume if bgs_flag
@KasperKalamity: These volume systems are implemented for the player, not the developer. Let's say the player is listening to music (not the game's music), but they're having trouble playing it on mute with no sound effects. That player can go in the menu and turn off the BGM, leaving the sound effects on. Or maybe they really like your game's soundtrack but can't stand the little menu 'blip blips' and such, they can turn off the sounds and still enjoy the game's music.
	
 
 
	
	
	
		
	Posts: 28
	Threads: 8
	Joined: Sep 2012
	
	
 
	
	
		At MechanicalPen and Kain Nobel - Thanks very much for your help - all working now!
Oh also at MechanicalPen yes text is missing because the game uses custom fonts which will need to be installed.