brainstorm
Member
I'm working on an Event save code for my game.... You know in some RPGs Where during cutscenes they have like Save Your Game? in a Text Box... Well thats what I'm trying to do.... Well Anyway here is the Script... You'll find an Error in it and If possible can you help me fix it....
Code:
class Interpreter
def command_save(file)
filename = make_filename(file) #"Save#{$game_system.file}.rxdata"
# Play save SE
$game_system.se_play($data_system.save_se)
# Write save data
file = File.open(filename, "wb")
write_save_data(file)
#file.close
# If file doesn't exist
unless FileTest.exist?(filename)
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play load SE
$game_system.se_play($data_system.load_se)
# Read save data
#file = File.open(filename, "rb")
read_save_data(file)
file.close
# Restore BGM and BGS
$game_system.bgm_play($game_system.playing_bgm)
$game_system.bgs_play($game_system.playing_bgs)
# Update map (run parallel process event)
$game_map.update
$scene = Scene_Map.new
end
def write_save_data(file)
#$game_system.file = file
# Make character data for drawing save file
characters = []
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
characters.push([actor.character_name, actor.character_hue])
end
# Write character data for drawing save file
Marshal.dump(characters, file)
# Wrire frame count for measuring play time
Marshal.dump(Graphics.frame_count, file)
# Increase save count by 1
$game_system.save_count += 1
# Save magic number
# (A random value will be written each time saving with editor)
$game_system.magic_number = $data_system.magic_number
# Write each type of game object
Marshal.dump($game_system, file)
Marshal.dump($game_switches, file)
Marshal.dump($game_variables, file)
Marshal.dump($game_self_switches, file)
Marshal.dump($game_screen, file)
Marshal.dump($game_actors, file)
Marshal.dump($game_party, file)
Marshal.dump($game_troop, file)
Marshal.dump($game_map, file)
Marshal.dump($game_player, file)
Marshal.dump($game_bully, file)
Marshal.dump($game_mini, file)
Marshal.dump($game_souls, file)
Marshal.dump($game_card, file)
Marshal.dump($game_languages, file)
$game_map.collision_map = nil
$game_map.height_map = nil
$game_map.swamp_map = nil
Marshal.dump($events, file)
#Marshal.dump($game_system, file)
end
def read_save_data(file)
# Read character data for drawing save file
characters = Marshal.load(file)
# Read frame count for measuring play time
Graphics.frame_count = Marshal.load(file)
# Read each type of game object
$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)
$game_bully = Marshal.load(file)
$game_mini = Marshal.load(file)
$game_souls = Marshal.load(file)
$game_card = Marshal.load(file)
$game_languages = Marshal.load(file)
$game_map.init_bitmaps
$events = Marshal.load(file)
# If magic number is different from when saving
# (if editing was added with editor)
if $game_system.magic_number != $data_system.magic_number
# Load map
$game_map.setup($game_map.map_id)
$game_player.center($game_player.x, $game_player.y)
end
# Refresh party members
$game_party.refresh
end
def make_filename(file_index)
return "Save#{file_index}.rxdata"
end
end