Values randomly getting set to null between passages?

tinzin

I swear JavaScript's type system is the absolute worst. I never know what the errors mean because they always seem like complete nonsense (got "this function only accepts anything" one time with Twine. Fun stuff).

Okay so basically, in the (default) passage, I have the following JS code:

set("fstats", function(){
    //contents unimportant, but this returns a string
});

And in another passage I have:

var fstats = get("fstats");
set("stats", fstats());

The second line of this, however, promptly returns a TypeError claiming that "fstats is not a function". Upon further investigation (I tried displaying it in an alert to debug), it appears that it somehow got set to null, or else just wasn't found for some reason. I've tried many different rewrites and in fact this was an attempted solution for Squiffy setting other variables to null, but it looks like the data just isn't being retained at all.

What's happening and how do I fix it?


thetruespin

I just had a skim but Squiffy doesn't preserve Javascript variables when a new section is loaded. The workaround is to store all your variables as Squiffy attributes and then convert them to JS variables when you need to use them.


Alex Warren

set and get read and store values to localStorage as JSON. This means you can store things like strings and numbers. But for some reason you're trying to store a function itself, which won't work as you can't store a function as JSON.

I'm not sure what you're trying to do, but why not just store the result of the function? i.e. invoke it in the call to set instead of get.


tinzin

Does this issue apply to Map and Array objects as well? What is compatible with JSON that I can use?
If Map and Array are supposed to work, then I'm stumped, because I'm getting the same issue when I actually store the function result. It simply doesn't save anything. It won't even save a string.


manowar

Can you put the code of your example?


Log in to post a reply.

Support

Forums