RPG Maker Forums

I'm creating a new class whose data I want to access by map id and event id, similar to Game_SelfSwitches.  So I've copied a number of functions from that class and renamed them, and have created my own value and setValue functions.  I've added DataManager commands to create a new object, update save file contents, and retrieve save file contents, to include this new class.


function Game_SelfSwitches() {
this.initialize.apply(this, arguments);
}

Game_SelfSwitches.prototype.initialize = function() {
this.clear();
};

Game_SelfSwitches.prototype.clear = function() {
this._data = {};
};

// ---------------------------------------------
function Game_EventLocations() {
this.initialize.apply(this, arguments);
}

Game_EventLocations.prototype.initialize = function() {
this.clear();
}

Game_EventLocations.prototype.clear = function() {
this._data = {};
}




This is how my new class looks, compared with $gameSelfSwitches, when I start a new game:

Code:
$gameSelfSwitches
Game_SelfSwitches {_data: Object, initialize: function, clear: function, value: function, setValue: function…}
  _data: Object
  __proto__: Game_SelfSwitches
$gameEventLocations
Game_EventLocations {_data: Object, initialize: function, clear: function, value: function, setValue: function}
  _data: Object
  __proto__: Game_EventLocations


However, when I save a game and load it, I've lost the prototype and all the functions associated with the class (the data is still there and looks correct), while $gameSelfSwitches looks as it should:

Code:
$gameSelfSwitches
Object {_data: Object, @: "Game_SelfSwitches", initialize: function, clear: function, value: function…}
  @: "Game_SelfSwitches"
  _data: Object
  __proto__: Game_SelfSwitches
$gameEventLocations
Object {_data: Object, @: "Game_EventLocations"}
  @: "Game_EventLocations"
  _data: Object
  __proto__: Object


Have I done something wrong with the save/load process?


var _Shaz_REP_DataManager_createGameObjects = DataManager.createGameObjects;
DataManager.createGameObjects = function() {
_Shaz_REP_DataManager_createGameObjects.call(this);
$gameEventLocations = new Game_EventLocations();
};

var _Shaz_REP_DataManager_makeSaveContents = DataManager.makeSaveContents;
DataManager.makeSaveContents = function() {
var contents = _Shaz_REP_DataManager_makeSaveContents.call(this);
contents.eventLocations = $gameEventLocations;
return contents;
};

var _Shaz_REP_DataManager_extractSaveContents = DataManager.extractSaveContents;
DataManager.extractSaveContents = function(contents) {
_Shaz_REP_DataManager_extractSaveContents.call(this, contents);
$gameEventLocations = contents.eventLocations;
};








Edit: I think I've solved it ... the only difference between the two was that my definitions were inside the (function() {...}); block of my plugin, and Game_SelfSwitches was defined at the higher level.  When I moved my Game_EventLocations functions above that block, so they were at the same level, it worked - the save file has the correct prototype.


I don't understand the logic behind this.  Could someone please explain it to me?

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,049
Messages
1,018,547
Members
137,835
Latest member
yetisteven
Top