Remembering Variables and the Back History Button

Please specify version and format if asking for help, or apply optional tags above:
Twine Version: 2.3
Story Format: SugarCube 2

So I’ve got a bit of an idea I’d like to implement for my story, and I’ve figured out how to mostly make it do what I want, except I’m running into issues related to the title of this post.

The short version of what I’m trying to accomplish is: I want to have multiple links throughout the story that will take the reader to a separate dedicated passage, which gives them more information about whatever entry they clicked on, and at the same time “unlocking” that passage in a master list of passages that default to “locked” until seen once by the player, and finally allow them to return to the location in the story they were at before clicking the link.

So to explain what I’ve done already in more detail, I have another passage that’s linked from the main title screen of the story called simply “Encyclopedia” which starts out with all entries “Locked” by default. I have a simple if statement in place that checks to see whether or not a unique variable associated to each entry is True or False, with a message that says: “Read the story to find out more about this entry!” by default when set to False, and when set to True, it displays that unlocked Encyclopedia entry instead.

As the player reads the main story, each time they click on one of those story links and are taken to the specific entry’s passage, I also want to have it unlock that entry from the Encyclopedia. That way they can easily reference any of their unlocked entries right from the title screen.

So far I’ve managed to accomplish this using a combination of Setter Links in the story to set the entry specific variable to true when a given link is clicked on, and on the individual passage dedicated to each story link I’ve added the <<remember>> bit of code to toggle simple ON/OFF boolean checks in these variables to see if the player has visited a given passage yet or not.

So an example Setter Link I’m using just to test functionality of a story link looks like this:
[[Sample Text Variable 1|Sample Variable 1 Passage][$testcase1 = true]]

And on the resulting story passage test page I have a placeholder text message for now that will eventually be the same entry as in the Encyclopedia listing, and the passage starts with the following code:
<<remember $testcase1 is true>>

I then added a simple link at the bottom of each individual entry’s passage in the story to “Click here to return to the story” which sends them back to the passage they were at before clicking the story link.

All of the above is working as I have intended. However, the problem I am running into is that, if the user ignores the link that takes them back to the story, and instead uses the Back Navigation button built into the UI menu, the natural functionality of that button causes Twine to essentially “forget” that the unlock variable was set to true.

So the reader who uses the back history button returns to the story after reading the story link’s passage, but without unlocking the associated Encyclopedia entry because the variable doesn’t stay “remembered” like it did when using the “click here…” link, which I’m guessing is because the engine sees that link clicking action as moving forward rather than the stepping-backward functionality of the UI button.

One idea that I imagined might work as a possible solution to this was temporarily disabling the back history button’s functionality in the UI just on the specific passages after clicking each of these story links, and then re-enabling it on returning to the main story. I found some resources and seemingly simple-to-implement solutions about disabling the functionality of the back button completely, but I’m less keen on that idea, as I’d like for it to still work elsewhere in the game if possible.

The other idea that I thought of was the more obvious and ideal solution of getting Twine to somehow remember the state of the boolean variables as being set to True regardless of whether or not a link was used or the back button was used to navigate, and I wouldn’t be surprised if it was something simple that I am unaware of or simply overlooking.

I haven’t had any luck so far finding information about either of those things though. It’s highly possible I am implementing something incorrectly or making a simple error in my lack of understanding and experience. So I figured I would ask for help and see if anyone could steer me in the right direction.

I’m a new user to Twine in general and the forums as well, with next to no prior HTML/CSS knowledge, so your patience is appreciated, as is any information or directions folks might be able to provide for this. Thanks in advance for your time.

I personally would just disable the UI back button permanently depending on the Twine flavor - In any game that keeps track of world state, you rarely want the player to go back when you don’t specifically want them to. You just have to make sure you always include a “return to story” link and avoid trapping them in any given passage.

In AXMA, there are separate macros for “Back” links (which works like the back button, undoing variables) and “Return” links (which goes back one passage, retaining variable state.) I always leave the UI back button in just for troubleshooting and then remove it for release.

1 Like

Thanks for your response. After reading what you wrote, I thought it over more carefully, and I’m having a hard time thinking of reasons why I would need the player to backtrack during the main story aside from my examples in my original post. So I think your suggestion of disabling the back button completely has promise, despite my earlier misgivings about that idea.

You also helped me realize that if I really need that sort of functionality elsewhere, I can just reintroduce it using links to simulate “Back” and/or “Forward” options even in the main story passages, and have better overall control over the flow of things that way.

I hadn’t heard of AXMA before, but I looked it up after reading your post. It seems like it has a nice UI and feature set.

Thank you for your help and perspective. It may not be how I originally imagined it, but I think this at least gives me a reasonable way forward to accomplish what I have in mind.

1 Like

One other shortcut I’ve used if it helps you - depending on your Twine version you can put a header or some type of “display” macro on every page that sets a specific variable (I use $loc for “location”) to what passage the player is actually in. That lets you divert somewhere else temporarily and go several more passages deep (in passages that don’t include a header or display macro to change the $location variable - like a menu of several passages with stats and inventory or whatever the player can jump around in for a while) and then just put in a generic link to “return to wherever they started from”. You just have to plan what sections of your game can be accessed globally.

1 Like

Thank you for that tip. It seems like an efficient approach, and I could see myself making use of something like that in the future when I’ve made more progress on my project.

It sounds like it could be a way to grant access to the full Encyclopedia feature for players, from any part of the game instead of just at the start like I have it now, and they’d be able to return to where they left off in the story after having accessed it.

I haven’t gotten far enough along yet to try adding extra menu options to the default UI menu so far, as I’m still trying to plan framework for the project and learn the basics of Twine in general, but it sounds like now is an ideal time for me to take these sorts of things into consideration.

At the very least, I can see something like this being useful for when I’m ready to start tackling those features. Thanks again for your helpful input.

1 Like