How to load a savefile?

Status
Not open for further replies.

Lu_

Veteran
Veteran
Joined
Sep 26, 2019
Messages
41
Reaction score
14
First Language
German
Primarily Uses
RMMV
I'm creating my own title screen with the HIME_PreTitleEvents and I want to load a file after a choice. I tried to use this one:
Code:
DataManager.loadGame(1);
$gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
$gamePlayer.requestMapReload();
SceneManager.goto(Scene_Map);
$gameSystem.onAfterLoad();
To load file 1 but it's crashing. Here is my bug:

Unbenannt.PNG
 

waynee95

Inactive
Veteran
Joined
Jul 2, 2016
Messages
682
Reaction score
598
First Language
German
Primarily Uses
RMMV
What happens when you do this in a project without plugins?
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
275
First Language
German
Primarily Uses
While it will be fine doing so in many cases, in general loading and saving the game is not supposed to be done in the middle of the games update cycle (when event commands would be run).

At this point, the events to update for the frame are already decided, and switching to a different savestate will continue updating those events, but many references to other events, switches, the player character etc. will use the freshly loaded data instead, which might trip the game up.
I'd recommend using a plugin for this one to move the execution of your loading script outside the main update routine:
Code:
// --------------------------------------------------------------------------
//  After Map Update Routine
//
// @plugindesc Allows to reserve a script to be run after the map update
//     cycle.
// @help Use
//     $gameTemp.afterUpdate = function() {
//        // ... your script ... //
//     };
//     to move the execution of your script outside the map update cycle.
//     Scene switches caused by events (Battle Processing etc.) and the
//     message box will take precedence over the reserved script.
//
//     It's recommended to put this as close to the bottom of your plugin
//     list as possible.
// --------------------------------------------------------------------------

(function() {
 
   var sceneMapUpdateMain = Scene_Map.prototype.updateMain;
   Scene_Map.prototype.updateMain = function() {
       sceneMapUpdateMain.call(this);
       if ($gameTemp.afterUpdate && this.isAfterUpdateOk()) {
           var callback = $gameTemp.afterUpdate;
           $gameTemp.afterUpdate = null;
           callback();
       }
   };
 
   Scene_Map.prototype.isAfterUpdateOk = function() {
       return this.isSceneChangeOk();
   };

})();
This should allow to alter your script call to
Code:
$gameTemp.afterUpdate = function() {
    DataManager.loadGame(1);
    $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
    $gamePlayer.requestMapReload();
    SceneManager.goto(Scene_Map);
    $gameSystem.onAfterLoad();
};
to move the execution of your script call and finish updating events and player first.
(Haven't tested the plugin yet though, but in general this should be a way to go)

As a sidenote, the
Code:
    $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
    $gamePlayer.requestMapReload();
part is usually only done to reset the current map if the game has since been updated. It resets all events and parallel processes, which you might not want when loading the game normally. If that is the case you can make this part conditional and only reset the map if you updated your project since (the default loading process):
Code:
if ($gameSystem.versionId() !== $dataSystem.versionId) {
    $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
    $gamePlayer.requestMapReload();
}
 

Lu_

Veteran
Veteran
Joined
Sep 26, 2019
Messages
41
Reaction score
14
First Language
German
Primarily Uses
RMMV
What happens when you do this in a project without plugins?
Without plugins its working fine. I guess its the way i tried to save the game. I used this
Code:
$gameSystem.onBeforeSave();
DataManager.saveGame(1);
to save the game. and if i use the normal save command from the menu its working with the plugins. i guess i have to put something in the code that saves the plugins?

$gameTemp.afterUpdate = function() { DataManager.loadGame(1); $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y); $gamePlayer.requestMapReload(); SceneManager.goto(Scene_Map); $gameSystem.onAfterLoad(); };
Tried this and still getting the same error
 
Last edited by a moderator:

Lu_

Veteran
Veteran
Joined
Sep 26, 2019
Messages
41
Reaction score
14
First Language
German
Primarily Uses
RMMV
I solved it on my own. This thread can get closed.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,842
Reaction score
5,225
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,096
Members
137,587
Latest member
Usagiis
Top