Load game script call?

RamminRyan

Warper
Member
Joined
Jan 8, 2015
Messages
4
Reaction score
0
First Language
English
Primarily Uses
Hey guys. So this may be something simple but I've looked everywhere and can't find anything. I 'm creating an menu screen through events and currently working on the load game function. I've set up an interactive menu through pictures and switches and I need to make an event that when the player presses the enter button it will load a certain save file. I'm only looking to use 3 save files using a conditional branch (script call button press) if possible.

In short how can I program "load file A" into a simple conditional branch.

Thanks for reading and your time.
 

Wavelength

Pre-Merge Boot
Global Mod
Joined
Jul 22, 2014
Messages
4,588
Reaction score
3,836
First Language
English
Primarily Uses
RMVXA
If you're literally just trying to load a single file (as it exists on your computer), you can use a command similar to the following:

$data_actors = load_data("Data/Actors.rvdata2")The left hand side should be an object (such as $data_actors or a custom object like $external) and the right hand side should be load_data("x") where x is the directory and name of the file inside your main project folder.  Be careful about encrypting your project - only certain folders (such as "System") will be accessible once you do encrypt it.

However, I think that what you're trying to do here is to replicate all of the system's default "Load" behavior for when you select a game file to load.  I cobbled together a few methods from the Scene_Load class to come up with what you see below, and I imagine it will work but I don't have time to test it now.  I think it will do what you need (the main legwork is being done by the DataManager's load_game method), but just to be safe, I recommend you start a new, clean, "dummy" project and thoroughly test this script with it first because it's always risky to play around with existing saved data.

if DataManager.load_game(@index) Sound.play_load SceneManager.scene.fadeout_all $game_system.on_after_load SceneManager.goto(Scene_Map) else Sound.play_buzzer endThis is intended for insertion into any event in the game.  If you want to add it to a Scene in the script editor (rather than an event on a map or a common event), then you should replace the SceneManager.scene.fadeout_all lines with simply fadeout_all  .

EDIT: Per post #4, it looks like the above does work.  However, @index is obviously not defined inside an event on the map, so you should replace it with the appropriate number (0 for File #1, 1 for File #2, 2 for File #3, etc.).
 
Last edited by a moderator:

KanaX

Just being a mouse
Veteran
Joined
Apr 3, 2013
Messages
1,463
Reaction score
1,285
First Language
Broken English.
Primarily Uses
N/A
DataManager.load_game(x)
Sound.play_load

SceneManager.scene.fadeout_all

$game_system.on_after_load
SceneManager.goto(Scene_Map)

Where x is the number of your save file - 1
 

Actually thank you for asking, because I wanted to use a similar feature too!
 

RamminRyan

Warper
Member
Joined
Jan 8, 2015
Messages
4
Reaction score
0
First Language
English
Primarily Uses
Thank you both for your answers. This has solved a problem that I've been dealing with for quite some time now. If anyone else stumbles upon this thread with the same problem then remember that file one's index equals 0. File 2 is 1 ect.
 

Wavelength

Pre-Merge Boot
Global Mod
Joined
Jul 22, 2014
Messages
4,588
Reaction score
3,836
First Language
English
Primarily Uses
RMVXA
Glad it worked for you!

Nice catch on the @index - that was sloppy of me.  As you said, it should be replaced with the appropriate number since it's not defined inside an event on the map.
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
536
Reaction score
249
First Language
German
Primarily Uses
Might want to add a note:
 

If you load a savestate directly within an event, it won't cancel the frame update process the script command was executed in. The game will continue to update all (common-)events that were active before the load process.

However, if one of them affects game data (like a control variables command in a parallel process) it affects the recently loaded data instead.

It's unlikely something like this will happen, but as I don't know how the event menu is set up, it might not hurt to be aware of it.
 
Last edited by a moderator:

AnthroMP

Kawaii
Member
Joined
May 1, 2015
Messages
28
Reaction score
0
First Language
English
Primarily Uses
(sorry for bump)

But will this work for XP?
 

Zeriab

Huggins!
Veteran
Joined
Mar 20, 2012
Messages
1,200
Reaction score
1,256
First Language
English
Primarily Uses
RMXP
No it will not. The code managing the save data loading is quite different and not very nice structured in XP.

I suggest adding this piece of code in a script section of it's own. As long as it's above Main it shouldn't matter where you place it.

class Interpreter  def load_game(file_num)    scene_load = Scene_Load.new    # File number is 1-based while file index is 0-based    filename = scene_load.make_filename(file_num - 1)    scene_load.on_decision(filename)    $game_temp.last_file_index = file_num - 1  end   def save_exist?(file_num)    scene_file = Scene_File.new('')    # File number is 1-based while file index is 0-based    filename = scene_file.make_filename(file_num - 1)    return FileTest.exist?(filename)  endend
To load save file 2 (Save2.rxdata) use the following script call

load_game(2)
To check whether Save2.rxdata actually exists use the following code in a Conditional Branch

save_exist?(2)
*hugs*

 - Zeriab
 

Raikiri91

Villager
Member
Joined
Aug 30, 2014
Messages
23
Reaction score
0
First Language
English
Primarily Uses
RMVXA
Maybe this was mentioned and I overlooked it, but is there a way to check for and load most recently saved file instead of just defining a specific file?
 

Zeriab

Huggins!
Veteran
Joined
Mar 20, 2012
Messages
1,200
Reaction score
1,256
First Language
English
Primarily Uses
RMXP
Look at how the default scripts decide which savefile to choose.
Use that logic for choosing which file to load.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Look, I get that it's illegal, but...
It just happen we got P7 as booth number, so i draw Girls Frontline's P7 in this
Stream will be live shortly! Going to start with some Minecraft spriting, and might switch mid-stream. Depends~ Feel free to drop by!
MushroomCake28 wrote on Finnuval's profile.
Glad to see you're back! I was wondering what you've become! It's been a while since we spoke to each other!
zachb wrote on Human_Male's profile.
I know this was months ago, but I don't completely understand the lunatic states program (how you set it up). I just want to apply a stone state (and death) to a character after x amount of time. Can you show me an example of how to set it up?

Forum statistics

Threads
93,468
Messages
912,744
Members
123,004
Latest member
Lysenthe
Top