Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Double function links/Back to story links.

I have links in my storymenu which open passages (standard) but then I want them to alter their function to switch back to the last story passage when clicked again.

How can I do this?

I'm guessing I'd have to use tags in non-story passages (like stat sheets and maps) that identify them as such with an if statement attached to the storymenu link, asking if I'm in a non-story passage.

Thanks in advance!

I'm currently using Sugarcube 2 or just Sugarcane.


  • Previous() can be used to go back to the last passage (page, in HTML parlance). You need to be really careful with using this however, since it is basically using the back/history function. If you don't know what passage previous() will take them back to, then you don't want to use it.

    For example, let's say I made an RPG in Twine and wanted to have help files that are passages that are linked in other passages that have elements I want explained to the players. I put the following link in one of those help passages:


    This is fine and works perfectly... except, what if I have further links in the help passage that lead to other help passages? Then previous() doesn't work, because we're more than one step away from the original passage. If previous() doesn't suit your needs, you'll have to use normal passage links, perhaps with conditions (like you mentioned).
  • Yeah, that's not really what I want. I know now the <<back>> macro. Is there any difference between that and previous() ?

    Either way I don't think that's gonna help me but thanks for your comment.
  • edited April 2016
    Are you using Sugarcube? If so...

    Here's a better solution for multiple passages. Put this setter link in the main story passage you're starting from:


    Where helpfile is the name of the first passage you're going to. In that passage (and all passages after it in your chain, I'm using "helpfile" because that's the only situation where I tend to use this) you can put:


    If you're not using sugarcube, the syntax will be different. It used to be something like state.history[0].passage.title for other story formats, I'm not sure if that still holds true.

    Let me know if this helps.

  • Thanks, I'll have a play about when I get a chance :)
  • I'm mostly using sugarcane atm fyi. I looked into different formats a bit and decided that Sugarcube 2 sounded like a good bet. I got it and had a go but I think I got frustrated that what little I'd learned on sugarcane, seemed to go out the window and the debug bit on the ui bar irritated me because when I test a game, I want to know what it looks like and I want to put links n stuff on the ui besides.

    So the answer to your question essentially is no. I'm not using Sugarcube but I might go back to Sc2 at some point so learning both cane and cube sounds like a good idea. Then I can get a better idea of which is best for me. (Possibly neither).

    As for the setter links for multiple passages that you offered; I'm not sure it's what I was looking for but I'll give it a go in both formats as I'm sure it'll be useful to know in any case.

    I'll have a fiddle when I get a moment.

    Thanks again!
  • edited April 2016
    I just tested in Sugarcane.

    passagenametogoto][$last=state.history[0].passage.title works for that storyformat and I'd assume all others. Sugarcube does things a little differently--I can certainly understand issues with it, I had the same when I switched to it initially.

    Once you've gone through that initial setter link, at any further passage down the line you can have a $last passage that will go back to whatever passage $last was set at.

  • Thanks!

    ...OK, I had a go. I'm not sure how to set a passage as a variable.

    How do I use this exactly?


    I'm still a bit confused about how you're implementing this, how it works, what it is or if it's even what I need.

    Just to clarify, I want a link in the UI bar which does two things.

    1. Opens an inventory passage or suchlike with links to further non-story passages.
    2. Changes when clicked, to a link that would close said passages. That link would revert to the original link when clicked again.

    For instance, in the UI bar you might have a link called 'Inventory'.
    Click on that link and it changes to 'Close Inventory' whilst opening up your inventory. Even if you open up new passages within your inventory, the 'Close Inventory' link will be able to direct you to your last story passage.

    If this is what you're trying (so very patiently) to show me, please try again! :S
  • edited April 2016
    The following should do what you want in Sugarcane:
    <<if $_return>>\
    [[Close Inventory|$_return][$_return to ""]]\
    [[Open Inventory|Inventory][$_return to passage()]]\

    The <<if>> macro selects the correct version of the link depending on whether the $_return variable is set to a non-empty string. The <<if>> works here because StoryMenu is processed each turn.

    If $_return is set to a non-empty string, that means the inventory is open and the value of $_return is the passage to return to. When clicked, the yielded "Close Inventory" link sends the player to the $_return passage and sets the value of $_return to the empty string.

    If $_return is set to the empty string, that means the inventory is closed and the value of $_return is the empty string. When clicked, the yielded "Open Inventory" link sends the player to the "Inventory" passage (change that to whatever your inventory passage is named) and sets the value of $_return to the name of the current passage.
  • Yes! That's perfect TME - and thank you for the explanation (which I'll probably have to read over a few times before it clicks) Thank you both.
Sign In or Register to comment.