Xyphien Forums

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

[Tutorial] The best way to append data to the save file


Staff member
Resource Team
For the longest time, it's been a pain in my side figuring out how to append information to a function that ends up returning a value. It turns out it was incredibly simple, I was just thinking a little too linear. Let's look at the original code for adding data to the save file.

DataManager.makeSaveContents = function() {
    // A save data does not contain $gameTemp, $gameMessage, and $gameTroop.
    var contents = {};
    contents.system       = $gameSystem;
    contents.screen       = $gameScreen;
    contents.timer        = $gameTimer;
    contents.switches     = $gameSwitches;
    contents.variables    = $gameVariables;
    contents.selfSwitches = $gameSelfSwitches;
    contents.actors       = $gameActors;
    contents.party        = $gameParty;
    contents.map          = $gameMap;
    contents.player       = $gamePlayer;
    return contents;
If you're asking "How do I alias that? It returns the contents", well my friend, you're just like me. It's time we settle this little issue once and for all. For starters lets create an alias variable like always!
var dm_save = DataManager.makeSaveContents;
Now all we need to do is create a variable called contents and make it equal to dm_save by using this method.. Prepare to laugh at how simple it is.
DataManager.makeSaveContents = function() {
        var contents = dm_save.apply(this, arguments);
        contents.upprom = romEntities;
        return contents;
.apply might not even be needed, but I know for a certainty that it works without error. Afterwords we simply append the added data by typing contents.your_data = data, then return the contents variable we created.

Needless to say, loading is just as simple, but that part was never really a problem.
var dm_load = DataManager.extractSaveContents;
    DataManager.extractSaveContents = function(contents) {
        dm_load.apply(this, arguments);
        $dataUppRomance    = (typeof contents.upprom != 'undefined') ? contents.upprom:[]
I hope this somehow helps people who are like me (not very good at coding lol, and probably too lazy to learn how to properly code, or simply isn't that interested).