Posts: 627
Threads: 38
Joined: May 2009
I tried to force a save using
file = File.open(filename, "wb")
write_save_data(file)
file.close
in a call script, but I keep getting a name error in the interpreter for the word filename. How exactly am I supposed to do this without using a full script. I only want it to force a save at the end of a chapter and when using certain items. So I don't really need a full script for this.
My partner in crime = TREXRELL
Posts: 11,212
Threads: 648
Joined: May 2009
My dear Yin,
You may not need a full script for this, but allow me to present one to you just in case. Punk himself penned it.
XP - Force Save before something
I believe you merely call $scene =Scene_ForceSave2.new to bring up the save screen where you choose what slot to use.
Posts: 627
Threads: 38
Joined: May 2009
Ok, this works, but how will I make it automatically save over the slot that is in use... To prevent cheating. So I don't want the player to choose. I mean, they can still cheat if they put their mind to it and save in a different slot before using the item then it forces the save over the slot while they can still load the other save.
My partner in crime = TREXRELL
Posts: 11,212
Threads: 648
Joined: May 2009
Ah. So what you are doing is making it so the player starts a game with a specific save slot which he uses throughout that one game. If he decides to start over, he can use the second slot (as an example), but your savegames can only be performed in the slot you started with.
Is that the case? You start off by having the game force an initial 'save' before the story starts?
Posts: 627
Threads: 38
Joined: May 2009
If I have to. That makes more sense. So how would I make it so that it forces an initial save?
My partner in crime = TREXRELL
Posts: 11,212
Threads: 648
Joined: May 2009
Well, for an initial 'SAVE" at the start of the game, you should also store a variable/value like $gameslotnumber which indicates the save slot you're using. It'll be based on the index of the save slot window.
You would acquire this same $gameslotnumber when you load a game from the title screen, so this number will be in memory for any and all 'saves' you use.
I guess this makes it so saves are even easier as you only can use one slot. ;) The same one slot throughout the game.
And with this one value, you generate the filename, like...
Code:
#--------------------------------------------------------------------------
# * Make File Name
# file_index : save file index (0-3)
#--------------------------------------------------------------------------
def make_filename(file_index)
return "Save#{file_index + 1}.rxdata"
end
Ripped from the default system.
Posts: 627
Threads: 38
Joined: May 2009
OK, I got the force save when pressing new game part. I just added this
Code:
$game_temp.save_calling = true
$scene = Scene_Save.new
to scene title. If you press cancel it takes you back to the title screen and when you choose a save spot, it takes you to the game. So that works pretty well for the most part. Now, the hard part (for me at least) is finding which file it was saved to.
on_cancel I put
Code:
if $game_system.save_count == 0
$scene = Scene_Title.new
That's why it goes back to title screen. I don't know if that is the best way to do it.
My partner in crime = TREXRELL
Posts: 11,212
Threads: 648
Joined: May 2009
Remember this in Scene_File's update method?
Code:
# If C button was pressed
if Input.trigger?(Input::C)
# Call method: on_decision (defined by the subclasses)
on_decision(make_filename(@file_index))
$game_temp.last_file_index = @file_index
return
end
Try adding a
$gamesaveindex = @file_index in there, and then reference it when you make the savefile name for later use in saves:
Code:
return "Save#{$gamesaveindex + 1}.rxdata"
... or something.
Posts: 627
Threads: 38
Joined: May 2009
Ok, I'll try this out now.
EDIT: Ok I got it working!
My partner in crime = TREXRELL
Posts: 11,212
Threads: 648
Joined: May 2009
Way to go! :)
Well, this topic is resolved.