How to have links to passages in the UI/Sidebar menu SugarCube 2.31.1

I wanted to add some permanent links to the sidebar. like to a Stat Passage/button. Or a Check Watch passage/button.
I’ve tried to do it on my own but I am real bad at javascript. Ill continue trying, but help would be awesome. thanks!

PS:
Taking a bunch of coding classes while my school is remote. and they start with html/css/javascript. So my questions should start to lessen over the next few months.

You can use either of the following Special Passages to add ‘links’ to the left sidebar:

  1. StoryMenu - which can be used to add ‘buttons’ to the menu area of the sidebar.
  2. StoryCaption - which can be used to add any type of content, including links & buttons.
1 Like

thank you so much!

Note that if you’re using such UI bar linked passages in combination with the <<return>> macro, or something functionally equivalent to that, there are two problems that you’ll need to make sure you avoid:

1.) Re-triggering code. If you go to “Passage X”, which gives the player the an additional 100 coins, then go to the “Stat Passage”, and then return to “Passage X”, the player will receive an an additional 100 coins again. They could just keep going back and forth between those passages as an “infinite money” trick.

To avoid that, any code which accumulates things, such as adding or subtracting values, or otherwise would have a cumulative effect, or any code which would undo what was done in the UI bar linked passages, instead of doing those things when entering a passage, they should be done when exiting the previous passage(s).

To take our previous example, to fix adding 100 coins when entering “Passage X” like this:

<<set $coins += 100>>

you would remove that line from “Passage X”, and instead you should do something like this in any passage which would send you to “Passage X”:

<<link "Receive your reward." "Passage X">>
	<<set $coins += 100>>
<</link>>

  - or -

[[Receive your reward.|Passage X][$coins += 100]]

Either of those two methods would work to prevent the problem, because they both add 100 coins just before sending you to “Passage X”. Now you can safely return from your UI bar linked passages to “Passage X”, and it won’t add more coins each time.

2.) Ping-ponging return loops. The other problem would occur if you have two or more UI bar linked passages that you could go to. What happens is that, if you go from one UI bar linked passage to another, now the “return” link will just send you back and forth between those two UI bar linked passages, because they’ll always be the previous passage that you just left.

To avoid that problem, you should use something like the “Arbitrarily long return” tip from the SugarCube documentation. That section provides code showing how to prevent that problem.

Hope that helps! :grinning:

2 Likes