I am having a bit of a head scratchy of an issue, and I'm hoping that maybe someone can assist. I'm not sure if I'm approaching this in a really stupid way or not, so please any constructive criticism is welcome.
I have created a new array called _stores that is a part of Game_System.
Intilization code is:-
Belone.Trade.Game_System_Intitalize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
Belone.Trade.Game_System_Intitalize.call(this);
this._stores = [];
};
I then push TradeStore objects to this array.
Within the TradeStore object are two arrays (importGoods and exportGoods). That are made up of objects (Goods - unsurprisingly).
Here is my code to add importGoods (the exportGoods is exactly the same).
this.addImport = function(item){
var newGood = {
good: item,
quantity: 0,
price: 0,
changeQuantity: function(amount){
var newQuantity = this.quantity + amount;
this.quantity = newQuantity ;
this.price = ((100 - newQuantity) * this.good.priceMultiplier).clamp(this.good.minPrice, this.good.maxPrice);
}
};
newGood.changeQuantity(0);
this.importGoods.push(newGood);
}
The issue is the changeQuantity function - this works exactly as intended on a New Game, however if I save the game and reload it then it reports the function as undefined, it can however read all other properties of the object, so the object is definitely getting saved, just not the functions within in.
I've tried creating some dummy functions and these have the same issue.
Have I done something wrong? Do I need to alter the save file operation to incorporate this functionality? Is there a better way of doing this?
Thanks in advance.
I have created a new array called _stores that is a part of Game_System.
Intilization code is:-
Belone.Trade.Game_System_Intitalize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
Belone.Trade.Game_System_Intitalize.call(this);
this._stores = [];
};
I then push TradeStore objects to this array.
Within the TradeStore object are two arrays (importGoods and exportGoods). That are made up of objects (Goods - unsurprisingly).
Here is my code to add importGoods (the exportGoods is exactly the same).
this.addImport = function(item){
var newGood = {
good: item,
quantity: 0,
price: 0,
changeQuantity: function(amount){
var newQuantity = this.quantity + amount;
this.quantity = newQuantity ;
this.price = ((100 - newQuantity) * this.good.priceMultiplier).clamp(this.good.minPrice, this.good.maxPrice);
}
};
newGood.changeQuantity(0);
this.importGoods.push(newGood);
}
The issue is the changeQuantity function - this works exactly as intended on a New Game, however if I save the game and reload it then it reports the function as undefined, it can however read all other properties of the object, so the object is definitely getting saved, just not the functions within in.
I've tried creating some dummy functions and these have the same issue.
Have I done something wrong? Do I need to alter the save file operation to incorporate this functionality? Is there a better way of doing this?
Thanks in advance.