- Xy$
- -0.10
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.
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!
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.
.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.
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).
JavaScript:
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;
};
JavaScript:
var dm_save = DataManager.makeSaveContents;
JavaScript:
DataManager.makeSaveContents = function() {
var contents = dm_save.apply(this, arguments);
contents.upprom = romEntities;
return contents;
};
Needless to say, loading is just as simple, but that part was never really a problem.
JavaScript:
var dm_load = DataManager.extractSaveContents;
DataManager.extractSaveContents = function(contents) {
dm_load.apply(this, arguments);
$dataUppRomance = (typeof contents.upprom != 'undefined') ? contents.upprom:[]
};