How to know what savefile is loaded?

LunaLuma

Warper
Member
Joined
Mar 19, 2019
Messages
2
Reaction score
0
First Language
French
Primarily Uses
RMMV
Hello! I'm new here and
(I don't speak english very well, so I'll try my best to be understable)
I wonder how to know what savefile is loaded with a script call.

I'm trying to make if the player die somewhere, when he'll load the game again and go back where he was died, he'll be alble to see blood where he died before.
I already tried Jackkel's Persistent Switches , but it affect all savesfiles. (and i would like that switches and variables are saved only one the actual savefile used by the player)
Then I found Olivia's Meta Controls, but the problem is the same, because even <Local Meta> affect all the save in the same in playthrough.


So I almost found a solution by combine Meta Controls and Autosave:

I already know "$gameSystem.onBeforeSave();DataManager.saveGame(x);". But in fact, I would like to make a save on the last loaded file (the file used by the player)
I tried "$gameSystem.onBeforeSave();DataManager.saveGame(DataManager.latestSavefileId());", but it works only with the last saved file so if I save my game in 3 slots (so there are 3 savefiles), then if I quit the game and I load the 2nd file, and I make an autosave by event with this script call, it will be saved on the 3rd, because it is the last saved file.)
So to solve this problem, I should force a 2nd save when the player loaded his file (So it will be the last saved file). But how i could guess what file was loaded by the player?

So is it posible to make a sort of conditional call script like this?

If slot 2 is loaded
script call: $gameSystem.onBeforeSave();DataManager.saveGame(2)


If slot 1 is loaded
script call: $gameSystem.onBeforeSave();DataManager.saveGame(1)


If slot 3 is loaded
script call: $gameSystem.onBeforeSave();DataManager.saveGame(3)


Or is there another solution to save only switches and variables values by script call or something?

I think I should make only one save slot in the game but i think it would be annoying to make a new game to have another end...


Thanks for your answer.
 

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
147
Reaction score
166
First Language
Danish
Primarily Uses
RMMV
There actually exists a field called _lastAccessedId in the DataManager which gives you the last used save file id. You probably thought you used this when calling latestSavefileId(), however latestSavefileId() actually does not give you the last accessed but the last saved.
Using this and having a savefile contain meta data then you can do something like this:
Code:
var MRP_TEST_GI_PLUGINCOMMAND = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        MRP_TEST_GI_PLUGINCOMMAND.call(this, command, args)
        if (command === 'SetMetaData'){
            var name = args[0];
            var value = "";
            for(var i = 1; i < args.length; i++){
                value += " " + args[i];
            }
            eval("$gameMetaData." + name + " = " + value);
        } else if (command === 'SaveMetaData') {
            DataManager.saveMetaData();
        }  
    };
 
    DataManager.saveMetaData = function() {
        for (var i = 0; i < this.maxSavefiles(); i++) {
            if (this.isThisGameFile(i)) {
                var json = StorageManager.load(i);
                var contents = JsonEx.parse(json);
                if(i == this.lastAccessedSavefileId()) {
                    contents.metaData = $gameMetaData;
                    var json = JsonEx.stringify(contents);
                    if (json.length >= 200000) {
                        console.warn('Save data too big!');
                    }
                    StorageManager.save(i, json);          
                    break;
                }
            }
        }
    }
 
    var MRP_TEST_DM_MAKESAVECONTENTS = DataManager.makeSaveContents;
    DataManager.makeSaveContents = function() {
        var contents = MRP_TEST_DM_MAKESAVECONTENTS.call(this);
        contents.metaData = $gameMetaData;
        return contents;
    };
 
    var MRP_TEST_DM_EXTRACTSAVECONTENTS = DataManager.extractSaveContents;
    DataManager.extractSaveContents = function(contents) {
        MRP_TEST_DM_EXTRACTSAVECONTENTS.call(this, contents);
        $gameMetaData           = contents.metaData;
    };
 
    var MRP_TEST_DM_SETUPNEWGAME = DataManager.setupNewGame;
    DataManager.setupNewGame = function() {
        MRP_TEST_DM_SETUPNEWGAME.call(this);
        $gameMetaData = {};
    };
With this then when you die the you should call the following plugin commands:
Code:
PluginCommand: SetMetaData deathLocations !$gameMetaData.deathLocations ? [YOUR_LOCATION] : $gameMetaData.deathLocations.concat([YOUR_LOCATION]);

PluginCommand: SaveMetaData
or with the following script:
Code:
$gameMetaData.deathLocations = !$gameMetaData.deathLocations ? [YOUR_LOCATION] : $gameMetaData.deathLocations.concat([YOUR_LOCATION]);
DataManager.saveMetaData();
or something like that. I do not know exactly how you plan on saving the locations.
 
Last edited:

LunaLuma

Warper
Member
Joined
Mar 19, 2019
Messages
2
Reaction score
0
First Language
French
Primarily Uses
RMMV
Thanks a lot to help me!
I'll test it right now

For the locations, this is just by event. I plan to activate a meta switch before set the game over when the player dies. So I put an event with a bloody tile which pop if this meta switch is ON (In my game, deaths are on precises tiles, I don't need to save a location).
I just need to save switches or variables on the savefile actually played by the user to put the blood and to change some things in the senario (because the player remembers of his deaths so his reactions are different).
 
Last edited:

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

Latest Threads

Latest Posts

Latest Profile Posts

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.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,863
Messages
1,017,053
Members
137,571
Latest member
grr
Top