Hey!
While working on my game I wanted to edit the titlescreen. You must know that in scripting I'm less than worthless,
so I was quite happy when something I put together actually worked, but when I selected something from the title commands,
some error popped up.
("Script 'Scene_Title' line 147: NoMethodError occured. undefined method 'commands' for #<Window_Command:0xd3dd4c78>")
But no matter what I do, i just can't find any problems. I hope you guys can help me. (i guess the whole script is just total crap :P)
Here's the script I use:
While working on my game I wanted to edit the titlescreen. You must know that in scripting I'm less than worthless,
so I was quite happy when something I put together actually worked, but when I selected something from the title commands,
some error popped up.
("Script 'Scene_Title' line 147: NoMethodError occured. undefined method 'commands' for #<Window_Command:0xd3dd4c78>")
But no matter what I do, i just can't find any problems. I hope you guys can help me. (i guess the whole script is just total crap :P)
Here's the script I use:
Code:
#==============================================================================
# ¦ Scene_Title
#------------------------------------------------------------------------------
# This class handles the title screen.
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# ? Set up the game
#--------------------------------------------------------------------------
def main
# Check if a battle test is being conducted
if $BTEST
battle_test
return
end
# Move database data to memory
$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")
# Draw system objects
$game_system = Game_System.new
# Draw title graphics
@sprite = Sprite.new
@sprite.bitmap = RPG::Cache.title($data_system.title_name)
#draw press z button
@start = Sprite.new
@start.bitmap = RPG::Cache.picture("start")
@start.x = 255
@start.y = 420
@start.zoom_x = 0.9
@start.zoom_y = 0.9
@start_flash = 0
# Draw the command window
s1 = "New Game" # 0
s2 = "Continue" # 1
s3 = "Quit" # 2
commands = [s2,s1,s3]
@commands = Window_Command.new(192, commands)
@commands.opacity = 255
@commands.back_opacity = 255
@commands.x = 210
@commands.y = 0
@commands.width = 200
@commands.visible = false
@commands.active = false
# Check if a game has already been saved. If so, enable the Continue button.
@continue_enabled = false
for i in 0..3
if FileTest.exist?("Save#{i+1}.rxdata")
@continue_enabled = true
end
end
# If continuing is allowed, select the Continue button.
if @continue_enabled == false
commands.delete("Continue")
end
# Play the title background music
$game_system.bgm_play($data_system.title_bgm)
# Stop any music effects or background sounds
Audio.me_stop
Audio.bgs_stop
# Update graphics and input
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
# Freeze graphics for transition
Graphics.freeze
# Erase the command window
@commands.dispose
# Erase the start button
@start.dispose
# Erase title graphics
@sprite.bitmap.dispose
@sprite.dispose
end
#--------------------------------------------------------------------------
# ? Repond to user input from the command window
#--------------------------------------------------------------------------
def update
# Update the command window
@commands.update
# Update the Start Button
@start.update
@start_flash = (@start_flash + 1) % 50 if @commands.visible == false
case @start_flash
when 25
@start.visible = false
when 49
@start.visible = true
end
if Input.trigger?(Input::C) and @commands.visible != true
@start.visible = false
@sprite.visible = false
@commands.visible = true
@commands.active = true
Audio.bgm_stop
$game_system.bgm_play($data_system.battle_bgm)
return
end
if Input.trigger?(Input::B) and @commands.visible = true
@start.visible = true
@sprite.visible = true
@commands.visible = false
@commands.active = false
Audio.bgm_stop
$game_system.bgm_play($data_system.title_bgm)
return
end
if Input.trigger?(Input::C) and @commands.active = true
# Branch by command window cursor position
case @commands.commands[@commands.index]
when "New Game" # 0
command_new_game
when "Continue" # 1
command_continue
when "Quit" # 2
command_shutdown
end
end
end
#--------------------------------------------------------------------------
# ? Start a new game
#--------------------------------------------------------------------------
def command_new_game
# Play decision sound effect
$game_system.se_play($data_system.decision_se)
# Stop Title BGM
Audio.bgm_stop
# Initialize new game
Graphics.frame_count = 0
$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 hero party
$game_party.setup_starting_members
# Set up opening map
$game_map.setup($data_system.start_map_id)
# Set up hero party's beginning location
$game_player.moveto($data_system.start_x, $data_system.start_y)
# Set up lead character's map sprite graphic
$game_player.refresh
# Refresh the map
$game_map.autoplay
$game_map.update
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# ? Continue a game
#--------------------------------------------------------------------------
def command_continue
unless @continue_enabled
$game_system.se_play($data_system.buzzer_se)
return
end
Audio.bgm_fade(800)
Audio.bgs_fade(800)
Audio.me_fade(800)
#$game_system.se_play($data_system.decision_se)
$game_temp = Game_Temp.new
$game_temp.last_file_index = 0
latest_time = Time.at(0)
i = 0
filename = make_filename(i)
if FileTest.exist?(filename)
file = File.open(filename, "r")
if file.mtime > latest_time
latest_time = file.mtime
$game_temp.last_file_index = i
end
file.close
end
$game_system.se_play($data_system.load_se)
file = File.open(filename, "rb")
read_save_data(file)
file.close
$game_system.bgm_play($game_system.playing_bgm)
$game_system.bgs_play($game_system.playing_bgs)
$game_map.update
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# ? Shutdown the game
#--------------------------------------------------------------------------
def command_shutdown
$game_system.se_play($data_system.decision_se)
Audio.bgm_fade(800)
Audio.bgs_fade(800)
Audio.me_fade(800)
$scene = nil
end
#--------------------------------------------------------------------------
# ? Start a battle test
#--------------------------------------------------------------------------
def battle_test
# Load information from database into memory
$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")
Graphics.frame_count = 0
# Initialize global classes
$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 battle
$game_party.setup_battle_test_members
$game_temp.battle_troop_id = $data_system.test_troop_id
$game_temp.battle_can_escape = true
$game_map.battleback_name = $data_system.battleback_name
# Set up music and sound
$game_system.se_play($data_system.battle_start_se)
$game_system.bgm_play($game_system.battle_bgm)
$scene = Scene_Battle.new
end
def read_save_data(file)
characters = Marshal.load(file)
Graphics.frame_count = Marshal.load(file)
$game_system = Marshal.load(file)
$game_switches = Marshal.load(file)
$game_variables = Marshal.load(file)
$game_self_switches = Marshal.load(file)
$game_screen = Marshal.load(file)
$game_actors = Marshal.load(file)
$game_party = Marshal.load(file)
$game_troop = Marshal.load(file)
$game_map = Marshal.load(file)
$game_player = Marshal.load(file)
if $game_system.magic_number != $data_system.magic_number
$game_map.setup($game_map.map_id)
$game_player.center($game_player.x, $game_player.y)
end
$game_party.refresh
end
def make_filename(file_index)
return "Save#{file_index + 1}.rxdata"
end
end