I'm just starting on my first ever twine attempt using Twine 1.4, and trying to get to grips with how variables work. In particular, I'm trying to understand how they change when the user chooses to use the back button in the story.
I can't seem to find the basic documentation on how history or state works but I gather that if a variable is set in one passage and then changed in a subsequent one, when a user goes back in their browser they would expect to see it go back to the prior value. Is that correct?
My basic example has a $testvar:
set to 1 in my start passage (effectively passage1)
set to 2 in passage2
unchanged in passage3
and set to 3 in passage 4
I would expect that when I go start -> passage2 -> passage3 -> passage4 it ends up as 3, which it does.
I would also expect that when in passage4 I click the back button in my browser and go back to passage 3 it would go back to the value of 2. This does not happen, it instead stays at a value of 3.
Do I need to manually manage my variable state somehow in script?
Apologies if this has been answered elsewhere, but I am having a really hard time finding clear info on how the history/state system works.
Comments
I used the following to test, and it wound back the history when I used browser back button:
(note: using TWEE notation, line starting with double colon (::) indicates a new passage with the related title.) Generally it is a better idea to give your reader links to navigate instead of relying on them using the browser back/forward buttons, you can do this by using the <<back>> (goes to previous passage and winds back history) and <<return>> (goes to previous passage and does NOT wind back history) macros.
I am using a fresh download of Twine 1.4.2 from twinery.org and running in current Chrome
Okay, my test story goes:
:: Start
Your story will display this passage first. Edit it by double clicking it.
<<set testvar = 1 >>
You are currently set to <<print testvar>>
[[Go to next passage|passage2]]
:: passage2
Not much going on here yet.
<<set testvar = 2>>
Except that you are now set to <<print testvar>>.
And now we go on [[to|passage3]]
:: passage3
And still not much going on.
You are still <<print testvar>>.
Moving on [[again|passage4]].
:: passage4
Not much going on here yet.
<<set testvar = 3>>
Except that you are now set to <<print testvar>>.
$
'; e.g.$testvar
).What you're doing in your example is creating auto-globals, since the vanilla story formats still allow that sort of thing. Those globals aren't part of the story history, and thus aren't affected when you roll the history back.
Is there somewhere that has the state and history system detailed a little more clearly? It didn't really seem to be mentioned in the introductory material I was reading on the wiki.