Implementation of menu system in SugarCube 2

- Posted in Coding by

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>>

Important notes regarding Harlowe 3 programming in Twine

- Posted in Coding by

Well, I've learned an important lesson regarding menuing in Harlowe. Don't set variables inside menu passages. I've also found some resources online including Tweego templates, SugarCube templates, etc.

I've also developed some interest in learning SugarCube, but I'm not entirely sure I have the programming chops for it.

I'm spending some time looking over [this][1] often-cited introductory material on Twine.

In the current story I'm writing, I've been able to figure out how to advance the story both by clicking on links (the hallmark of Twine) and by just clicking on or tapping the screen.

Here is the Save/Load code I'm currently using:

<div id="text_centered"><small> 
    {(link-repeat:'[Save]<saverepeat|')[
        (if: (save-game:"GameSlot1"))[
            (replace: ?saverepeat)[SAVE AGAIN!]
            (dialog: "#### Save Successful!")
        ]
        (if: not (save-game:"GameSlot1"))[
            (replace: ?saverepeat)[Save... Again?]
            (dialog: "### Save Failed...", "Bummer...")
        ]
    ]
    (link-repeat:'Load')[
        (if: (savedgames:) contains "GameSlot1") [
            (dialog: "### Loaded Save", "Yay!")
            (load-game:"GameSlot1")      
    ]
  (else:)[
    (dialog: "### No Savefile!", "Ah...")
  ]
]}
</small></div>