Variable drift?

I've got a large game I'm working on - 120,000 lines of code so far. Every so often in tried-n-tested routines, I'll see incomprehensible events occur - as if variables are changing inexplicably. I've added debug statements and carefully checked my variable names (to make sure I don't have any capital letters or are using them elsewheres). And when I run the game, I can see if fail (using debug to navigate) every so often.

I did delete the index.html file and haven't seen it fail since then. Anyone have anything they can add to this?

Anyone know any limits to number of variables, length of variable names, that sort of thing?


I don't think variables should drift, but attributes are kept in a LocalStorage; which in practice imposes a limit of 5MB. Whether it prompts the user to allow more space or just drops the least-recently-used ones depends on the browser.

(note that if you're playing Squiffy games online, this 5MB limit will be shared between all saved games on the same site. They're stored in a single dictionary, where the keys are made by appending the attribute name to the game ID. This means that playing a game which uses a very large number of attributes could cause the older ones from a completely different game being dropped. And the algorithm for deciding which ones to drop isn't constant between browsers - it could depend on any combination of how recently they were used, how recently they were changed, the size of the value, and other undocumented criteria)

This is one of the reasons I would try to avoid using attributes unless necessary; or deleting them when they're no longer needed.


That's horrifying! But I'd rather know than not. Thanks, you two. Is there even a way to delete attributes?

I usually @unset them if they're getting in the way, but that just makes them false. Though I guess, false is smaller than something like @set style_Handwriting=<meta name="viewport" content="width=device-width, initial-scale=1.0"><div style="color:black; font-weight:900; font-size:30px; line-height:1.44; font-family:Comic Sans MS, Comic Sans, cursive; max-width:auto; max-height:auto; background-repeat: repeat-y; background-size: auto; background-image: url('./Handwriting2.png');"">


mrangel - Hmmm. Thinking this over. But you said they delete the oldest first, right? Why would they delete the current ones that are actively being used?

Also, I'm seeing this when I do a build. But I think I see it when the game has been going on for a while. I've had on/off problems with it.


But you said they delete the oldest first, right?

The browser can choose which ones to drop based on whatever criteria the developers choose. In theory oldest is a good metric; in practice they're more likely to try weighing size against some formula to determine the probability that some value will be used again.


Ugh, so no firm control over what gets deleted. Well, good to know. At least that might explain some of the curious issues I've had.


I don't have my computer right now but would anything remotely like squiffy.removeItem("attribute"); maybe work?


I don't have my computer right now but would anything remotely like squiffy.removeItem("attribute"); maybe work?

Don't think there is such a function. You'd want to implement it by something like:

    squiffy.removeAttribute = function (attr) {
        if (squiffy.ui.settings.persist && window.localStorage) {
            window.localStorage.removeItem(squiffy.story.id + '-' + attr);
        }
        else {
            delete squiffy.storageFallback[attr];
        }
    };

This topic is now closed. Topics are closed after 180 days of inactivity.

Support

Forums