Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Remembering/forgetting all variables

I was just asked whether it was possible to make a macro that causes all variables in the story to be <<remember>>ed or <<forget>>, without needing to explicitly <<remember>> every one by name. So, I whipped this script up fast:

macros.forgetall = macros.rememberall = {
handler: function (a, name) {
var s = state.history[0].variables;
for (variable in s) {
if (s.hasOwnProperty(variable)) {
if (name == "forgetall") {
delete window.localStorage[macros.remember.prefix + variable];
delete s[variable];
} else {
window.localStorage[macros.remember.prefix + variable] = s[variable];
}
}
}
}
}
Usage: <<rememberall>> or <<forgetall>>. That's it. It's kind of rough, but should work.

Comments

  • thanks this is perfect :)
  • I wanted that as well. Thanks!
  • Flippping Awesome! Thanks L.
  • That's cool!

    I am a beginner with Twine and was thinking about persistence a lot.

    This saves my own properties perfect, but here's my stupid question: how to save internal information, like the visited-state and current passage? I simple wan't to pick up the story wherever the reader / player has left.
  • I'm looking for a way to use an external text file as a passage. Since [img[picture.jpg]] works, I was looking for something like [text[words.rtf]]. I noticed that this macro uses "window.localStorage" and was wondering if it's creating an external file. Unfortunately, I'm afraid I just don't quite understand what this macro does. Is it resetting all the variables to an external file?
  • Gray wrote:

    I'm looking for a way to use an external text file as a passage. Since [img[picture.jpg]] works, I was looking for something like [text[words.rtf]].

    This is not possible in HTML.
    By which I mean, it's "possible", but it's kind of pathetic and convoluted to actually make happen, so for the most part, it isn't.
    Gray wrote:
    I noticed that this macro uses "window.localStorage" and was wondering if it's creating an external file. Unfortunately, I'm afraid I just don't quite understand what this macro does. Is it resetting all the variables to an external file?
    localStorage is basically the same as a browser cookie, but much more robust and with bigger size limits.
  • Well, that's a shame. Thank you for responding.
  • Hey, this macro works for numbers but not strings, apparently? It returns my strings as 0. Any help you could give would be appreciated.

    edit: found fix
Sign In or Register to comment.