Howdy, Stranger!

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

"go to Previous Passage" code?

I use Sugarcube. I'm working on something where the player will travel through a lot of different passages, but there's always the option to click on this one button I have that will take them to a different passage, like a hub

Only problem is, once the person's at the hub from whatever passage they came from, how do I get them back to that specific passage?

Let's say the player starts in Passage1, and travels all the way to Passage12, then goes to the hub. How do I code in that when they hit the previous button, or whatever else, it returns them specifically to the one they just came from, rather than having to put them all the way back at a fixed passage like Passage1, and they have to redo everything.

Is there an easy way to implement this? I'd greatly appreciate any help with this problem.

Comments

  • edited June 2015
    I would set a variable inside the click on your way out from where you just left and have them always go back to the variable.

    So, like this, for example... assuming you have numbered passages as your text has suggested.
    [[Hub][$roomJustLeft to 1]]
    

    Just remember to rename the new passage because the auto-naming feature will jack it up.
  • edited June 2015
    Sage wrote: »
    I would set a variable inside the click on your way out from where you just left and have them always go back to the variable.

    So, like this, for example... assuming you have numbered passages as your text has suggested.
    [[Hub][$roomJustLeft to 1]]
    

    Just remember to rename the new passage because the auto-naming feature will jack it up.

    Hi Sage, thank you for commenting.

    It seems I've foolishly found an easy way to do what I'm asking.

    Simply using the <<back "Home">> command returns you to the previous passage with a link titled "Home"
  • That's actually CRAZY helpful. I didn't even know that existed.

    Thank YOU
  • It seems I've foolishly found an easy way to do what I'm asking.

    Simply using the <<back "Home">> command returns you to the previous passage with a link titled "Home"
    Note: The <<back>> macro rewinds the state history (i.e. it undoes state). From the description in the OP post, it seems like you simply want to return the player to the originating passage, not actually undo the history. If that's the case, then what you actually want to use is either the <<return>> macro (same syntax as <<back>>) or a link using the previous() story function. For example:
    /* Using the <<return>> macro */
    <<return "Home">>
    
    /* Using the previous() story function in a link */
    [[Home|previous()]]
    
  • Just a bit of extra info here.

    Note there is also the previous() function. It returns the passage name.

    For Harlowe, see this thread for more information: Incorporating the functionality of previous() in Twine 2?
  • Hi! Thanks a lot for this help.

    Would it be possible to use the <<back>> or <<return>> command using an image instead of a text for the link? Something like <<return "<img/return.jpg>">>, only that works :tongue:

    Thanks a lot

    (I post here because it's related to the topic, even though it's old, if it's wrong please let me know!)
  • Is there a way to change what the <<back>> command says? It seems to only say back. But I want it to say "Resume" for my games.
Sign In or Register to comment.