Help on hide toggles sugarcube 2

If you are requesting technical assistance with Twine, please specify:
Twine Version: 2.3.16
Story Format: SugarCube 2.36.1

Hi there. I’m trying to set up a link that toggles and reveals a players stats on the side ui bar.
My current code looks like this…

<<link "stats">>
	<<toggleclass "#stats" "hide">>
<span id="stats" class="hide">
Strength: -6 lol
Intelligence: You get the idea.....

And then in my Stylesheet…

.hide {
	display: none;

Now this works great. However, when I then change to a new passage it hides the stats again.
I’d like it to be a permanent toggle.

In short I would like a text that says “stats” on my left ui bar and when clicked instantly and permanently displays stats until clicked again

Any help would be greatly appreciated.

Unfortunately, when you change passage, everything in the UIBar is reevaluated. Then your “stats” section restart hidden. What may do the trick would be to use an <<if>><</if>> macro, associated with a story variable instead of a <<toggleclass>> macro.

You can use a variable that keeps track of the hidden or not state.

<<link "stats">>
  <<toggleclass "#stats" "hide">>
  <<set $hideStats to not $hideStats>> // toggles $hideStats between true and false
<span id="stats" @class="$hideStats ? 'hide' : ''"> // adds the 'hide' class if $hideStats is true
  Strength: -6 lol
  Intelligence: You get the idea...

Okay sweet, I’ll give these a try once I’m home and I’ll update on how it went. Thanks :pray: :blush: