So, for some reason I cannot modify values in a persist object. I set up a store, like this:
({
Shop: {
items: ["item", "item", "item"],
talk: function() {
ShowShop(this.items);
},
},
});
I then commence to trade and modify the list of items so it reads:
["item", "item", "item", "item"]Then I do this test on the persist object:
var world = JSON.stringify(persist.getWorldState());
Debug.alert(persist.getWorldState()[GetCurrentMap()].Shop.items);
Debug.alert(JSON.parse(world)[GetCurrentMap()].Shop.items);
And I get two very different results. The JSON object will only show the original list of items, while the direct source will show all of the items. Because of this issue I can't save modified lists of stuff, and I have no idea why.
I then see inside the persist code this gem:
/* Tie an existing object to a prototype. */
function tieToPrototype(obj, proto)
{
var protoTie = function () {};
protoTie.prototype = proto;
var newObj = new protoTie();
for (var p in obj) {
if (p in proto && typeof proto[p] == 'object')
newObj[p] = tieToPrototype(obj[p], proto[p]);
else
newObj[p] = obj[p];
}
return newObj;
}
And for some reason I think this may be what's interfering. If I can't solve this problem, then persist has sadly, defeated itself for me.
For one, persist will convert all arrays into objects. Ouch!
Furthermore I can't seem to do this:
persist.map().Shop.new_var = true;
When I go through the JSON motions, the value 'new_var' that I instantiated after the load had been stripped. Despite being added in after the fact, it won't save to file, calling 'toSource()' on the object also won't unveil it in it's list of fields, however if I use the '.new_var' field it's there; it exists. Tung seemed to have removed many idiomatic Javascript features in his persist wrapper. Can someone far brighter than me in this matter help me rewrite his code to not have this behavior?
Furthermore, values if changed produce whacky outputs. When I tack on a 'visited' member, set initially to false. I always get false back from it. Even if I set it to true... unless I'm using it directly within the scope of the person or map, then it
seems to work out. I have no idea why this is happening.
Edit:
Wait... It's working EVERYWHERE ELSE but that file of code. WTF?