Home Artists Posts Import Register

Content

If you're in the process of making a plugin and want to find out how you can add a variable to the games save file, it's a lot simpler than you think. You might be asking "how do I alias something that returns a value?" Well, to do this you need to make an alias first, this can be done like so:

 

var dm_save = DataManager.makeSaveContents;


this will copy the function "DataManager.makeSaveContents", but you probably already knew that. Here comes the magic. We're going to re-create the function like you would a normal alias, cept' this time we're going to create a variable called contents and set it equal to this value:

var contents = dm_save.apply(this, arguments);

then simply add to the content...

contents.my_variable = value;

I'm not exactly sure .apply is needed, but it'll probably prevent any weird compatibility issues if someones using a strange obscure plugin that for some reason gives the function arguments (I think...)? Now you should be set, just return contents like the original script does. it should look something like this:

 
var dm_save = DataManager.makeSaveContents;
   DataManager.makeSaveContents = function() {
   var contents = dm_save.apply(this, arguments);
   contents.my_data = value;
   return contents;
};


That my friend is how you properly alias the DataManager.makeSaveContents function.

Comments

No comments found for this post.