Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.
I want to add a sound test option to my menu. The problem is... I dont know how to tell it to play BGM or anything else, just System SE. (lol) New scripter, lol.
It is the only help i need. Any one know?
It's better to use the $game_system.bgm_play(audiofile) method rather than the Audio.bgm_play method. It provides compatibility with volume scripts and the such.
ok, ive givin my best shot at the script. I just need to find out what i did wrong. I have saved the scripts file to http://hosted.filefront.com/randpicturesinc/ it is half way down the page. I've edited the scene_title screen and added a scene_soundtest script, so i saved the whole scripts file. When you find the problem, can you tell me what I did wrong and tell me what you did to make it work. THANK YOU SOOOOOOO MUCH! :D :D ;D ;D
Where to start. Well first the code, than the explanation. If anything is unclear or not explained well by me just ask about it and I'll try to clarify as best I can. ;D
Code:
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# This class performs title screen processing.
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# If battle test
if $BTEST
battle_test
return
end
# Load database
$data_actors = load_data("Data/Actors.rxdata")
$data_classes = load_data("Data/Classes.rxdata")
$data_skills = load_data("Data/Skills.rxdata")
$data_items = load_data("Data/Items.rxdata")
$data_weapons = load_data("Data/Weapons.rxdata")
$data_armors = load_data("Data/Armors.rxdata")
$data_enemies = load_data("Data/Enemies.rxdata")
$data_troops = load_data("Data/Troops.rxdata")
$data_states = load_data("Data/States.rxdata")
$data_animations = load_data("Data/Animations.rxdata")
$data_tilesets = load_data("Data/Tilesets.rxdata")
$data_common_events = load_data("Data/CommonEvents.rxdata")
$data_system = load_data("Data/System.rxdata")
# Make system object
$game_system = Game_System.new
# Make title graphic
@sprite = Sprite.new
@sprite.bitmap = RPG::Cache.title($data_system.title_name)
# Make command window
s1 = "New Game"
s2 = "Continue"
s3 = "Sound Test"
s4 = "Shutdown"
@command_window = Window_Command.new(192, [s1, s2, s3, s4])
@command_window.back_opacity = 160
@command_window.x = 320 - @command_window.width / 2
@command_window.y = 288
# Continue enabled determinant
# Check if at least one save file exists
# If enabled, make @continue_enabled true; if disabled, make it false
@continue_enabled = false
for i in 0..3
if FileTest.exist?("Save#{i+1}.rxdata")
@continue_enabled = true
end
end
# If continue is enabled, move cursor to "Continue"
# If disabled, display "Continue" text in gray
if @continue_enabled
@command_window.index = 1
else
@command_window.disable_item(1)
end
# Play title BGM
$game_system.bgm_play($data_system.title_bgm)
# Stop playing ME and BGS
Audio.me_stop
Audio.bgs_stop
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of command window
@command_window.dispose
# Dispose of title graphic
@sprite.bitmap.dispose
@sprite.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update command window
@command_window.update
# If C button was pressed
if Input.trigger?(Input::C)
# Branch by command window cursor position
case @command_window.index
when 0 # New game
command_new_game
when 1 # Continue
command_continue
when 2 # Sound Test
# Switch to Sound Test Screen
$scene = Scene_Soundtest.new
when 3 # Shutdown
command_shutdown
end
end
end
#--------------------------------------------------------------------------
# * Command: New Game
#--------------------------------------------------------------------------
def command_new_game
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Stop BGM
Audio.bgm_stop
# Reset frame count for measuring play time
Graphics.frame_count = 0
# Make each type of game object
$game_temp = Game_Temp.new
$game_system = Game_System.new
$game_switches = Game_Switches.new
$game_variables = Game_Variables.new
$game_self_switches = Game_SelfSwitches.new
$game_screen = Game_Screen.new
$game_actors = Game_Actors.new
$game_party = Game_Party.new
$game_troop = Game_Troop.new
$game_map = Game_Map.new
$game_player = Game_Player.new
# Set up initial party
$game_party.setup_starting_members
# Set up initial map position
$game_map.setup($data_system.start_map_id)
# Move player to initial position
$game_player.moveto($data_system.start_x, $data_system.start_y)
# Refresh player
$game_player.refresh
# Run automatic change for BGM and BGS set with map
$game_map.autoplay
# Update map (run parallel process event)
$game_map.update
# Switch to map screen
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# * Command: Continue
#--------------------------------------------------------------------------
def command_continue
# If continue is disabled
unless @continue_enabled
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to load screen
$scene = Scene_Load.new
end
#--------------------------------------------------------------------------
# * Command: Shutdown
#--------------------------------------------------------------------------
def command_shutdown
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Fade out BGM, BGS, and ME
Audio.bgm_fade(800)
Audio.bgs_fade(800)
Audio.me_fade(800)
# Shutdown
$scene = nil
end
#-------------------------------------------------------------------------
# * Battle Test
#--------------------------------------------------------------------------
def battle_test
# Load database (for battle test)
$data_actors = load_data("Data/BT_Actors.rxdata")
$data_classes = load_data("Data/BT_Classes.rxdata")
$data_skills = load_data("Data/BT_Skills.rxdata")
$data_items = load_data("Data/BT_Items.rxdata")
$data_weapons = load_data("Data/BT_Weapons.rxdata")
$data_armors = load_data("Data/BT_Armors.rxdata")
$data_enemies = load_data("Data/BT_Enemies.rxdata")
$data_troops = load_data("Data/BT_Troops.rxdata")
$data_states = load_data("Data/BT_States.rxdata")
$data_animations = load_data("Data/BT_Animations.rxdata")
$data_tilesets = load_data("Data/BT_Tilesets.rxdata")
$data_common_events = load_data("Data/BT_CommonEvents.rxdata")
$data_system = load_data("Data/BT_System.rxdata")
# Reset frame count for measuring play time
Graphics.frame_count = 0
# Make each game object
$game_temp = Game_Temp.new
$game_system = Game_System.new
$game_switches = Game_Switches.new
$game_variables = Game_Variables.new
$game_self_switches = Game_SelfSwitches.new
$game_screen = Game_Screen.new
$game_actors = Game_Actors.new
$game_party = Game_Party.new
$game_troop = Game_Troop.new
$game_map = Game_Map.new
$game_player = Game_Player.new
# Set up party for battle test
$game_party.setup_battle_test_members
# Set troop ID, can escape flag, and battleback
$game_temp.battle_troop_id = $data_system.test_troop_id
$game_temp.battle_can_escape = true
$game_map.battleback_name = $data_system.battleback_name
# Play battle start SE
$game_system.se_play($data_system.battle_start_se)
# Play battle BGM
$game_system.bgm_play($game_system.battle_bgm)
# Switch to battle screen
$scene = Scene_Battle.new
end
end
Code:
#==============================================================================
# ** Scene_Soundtest
#------------------------------------------------------------------------------
# This class perfoms the sound test screen.
#==============================================================================
class Scene_Soundtest
# Add sounds into this hash following the pattern.
BGM_HASH =
{
0 => ['001-battle01','Battle Theme'],
1 => ['005-boss01','Boss Theme'],
}
#--------------------------------------------------------------------------
# * Object Initialization
# menu_index : command cursor's initial position
#--------------------------------------------------------------------------
def initialize(menu_index = 0)
@menu_index = menu_index
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make command window
options = Array.new
BGM_HASH.each_value {|text| options << text[1]}
@command_window = Window_Command.new(160, options)
@command_window.index = @menu_index
Audio.me_stop
Audio.bgs_stop
Audio.bgm_stop
Graphics.transition
loop do
Graphics.update
Input.update
@command_window.update
update_command
break if $scene != self
end
Graphics.freeze
@command_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update (when command window is active)
#--------------------------------------------------------------------------
def update_command
# If C button was pressed
if Input.trigger?(Input::C)
# Branch by command window cursor position
if BGM_HASH.has_key?(@command_window.index)
$game_system.se_play($data_system.decision_se)
# Play Battle Theme
sound = RPG::AudioFile.new(BGM_HASH[@command_window.index][0], 100, 100)
$game_system.bgm_play(sound)
else
# If the BGM isn't in the hash play the buzzer
$game_system.se_play($data_system.buzzer_se)
end
# If B button was pressed
elsif Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to Title screen
$scene = Scene_Title.new
end
end
end
Scene_Title wasn't creating Scene_Soundtest. To do that you need to use the method 'new', which acts as the constructor for objects in Ruby.
Next in the Scene_Soundtest department there were a lot of errors and bugs in this guy. There was no declaration of a class. Meaning that there was no line in there stating that any of the code below fell into Scene_Soundtest. The code for doing that is:
Code:
class Scene_Soundtest
Then we have main. The way Scenes work are by constantly retrieving input and updating elements like windows, sprites, text that gets drawn etc. To do this effectively we use a loop with the condition to break only if the scene changes:
Code:
def main
... # Initialize resources
Graphics.transition # Required so we can break the last Graphics.freeze from the last scene.
loop do
Graphics.update # Update the graphics.
Input.update # Update the input.
update # Call this scenes update.
break if $scene != self # If the scene has changed break from the loop
end
Graphics.freeze # Freeze so we can lead into the next transition.
... # Dispose of resources.
end
Your update_command was pretty garbled all and all. It shared scraps of code from various places. Never copy and pray. It will always bite you in the ass. Anyway here's what I did to help you out. It works hurray so what next. I made a hash that contains all the possible entries that you want to display at the TOP of Scene_Soundtest.
The key or the thing you see before '=>' is the index at which it will appear in the command window. If you skip a number you won't be totally screwed but you will have broken the system. The next part is actually an array. The first element is a string which represents the filename of the bgm. The second string is the name it will have when it appears in the command window.
Let's say we wanted to add '006-boss02' into the possible sounds we could play.