Implementation of menu system in SugarCube 2
The preferred way to implement menus in SugarCube 2 is to add the following code to your javascript section:
/* Trigger the following code at the start of navigation to a new passage. */
$(document).on(":passagestart", function (event) {
/* Make sure the current passage doesn't have a "noreturn" tag. */
if (!tags().includes("noreturn")) {
/* If it doesn't, then set $return to the current passage name. */
State.variables.return = passage();
}
});
And then, tag any menu passages (however deeply nested they may be) with 'noreturn', adding the following link to those menu passages:
<<link "Return" $return>><</link>>
→