Saving sidebar state between passage navigation

Twine Version: 2
Story Format: sugarcube2

I couldn’t find anything online about this so I decided to post here.

Is there a way to save the state of a sidebar between passage navigation?

Let’s say we have a bunch of buttons in the sidebar and when clicking on a button a dropdown with some information opens below it. Initialy, all dropdowns are open, but I want to allow the user to close those he finds unnecessary. For example, he wants the first and the third dropdown open, and the second one closed. The problem is, once he navigates to the next passage the sidebar will rerender and all the dropdowns will be open again.

I tried using local storage and “passage-done”, but inside “passage-done” I can only access the content inside the actual passage, and not the sidebar.

Any idea how this can be achieved?

I’m going to assume you’re using a StoryCaption special Passage do display your “bunch of (stateful) buttons”.

If you look at the Navigation Events documentation you will see that the contents of the StoryCaption passage is processed after that of both the ‘current’ Passage and the PassageDone special passage. And that the only event that fires after the processing of StoryCaption is :passageend.

If you want to change how the “bunch of (stateful) buttons” are ‘initially’ displayed each time a Passage Transition then simply code each of those buttons to use a variable combined with a <<if>> + <<else>> macro pair to determine which of two visual ‘states’ to display it in.

Obviously I don’t have access to whatever code you’re using to currently display the two states of a ‘button’, nor the code you’re using to store the current state within local storage. So I can’t show you how to alter it to achieve the above effect.

Thanks, Greyelf! This solved my issue. I don’t know why it never occurred to me to just use if statements for this. :sweat_smile: