I'm trying to save a class and load it again, the data is saved but the function ($myFood.add) no longer works. I've tried both adding the object to $gameSystem and hooking DataManager, neither work.
This is what I've got so far
This is what I've got so far
JavaScript:
(() => {
$myFood = null;
Food.prototype = Object.create(Food.prototype);
Food.prototype.constructor = Food;
function Food(){
this.initialize.apply(this, arguments);
};
Food.prototype.initialize = function() {
this._amount = 0;
};
Food.prototype.add = function()
{
this._amount+=1;
};
(function(alias) {
DataManager.createGameObjects = function() {
alias.apply(this, arguments);
$myFood = new Food();
};
})(DataManager.createGameObjects);
(function(alias) {
DataManager.makeSaveContents = function() {
var contents = alias.apply(this, arguments);
contents.mySaveProperty = $myFood;
return contents;
};
})(DataManager.makeSaveContents);
(function(alias) {
DataManager.extractSaveContents = function(contents) {
alias.apply(this, arguments);
var data = contents.mySaveProperty;
if (data) $myFood = data;
};
})(DataManager.extractSaveContents);
})();