Howdy, Stranger!

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

Going back to the very last passage with Harlowe

edited March 12 in Help! with 2.0
I'm trying to make a large document which has many index pages. Because the document is supposed to be rather sprawling, many mentions of certain topics will then link to those topics so that you don't have to go hunting for them elsewhere if you want clarification.

Normally, you could simply make a 'back' button by making a link which goes to the last passage, but that becomes more complex when there can be more than one possible passage that you came from. I've looked around, and previous() came up, but that's obviously for Sugarcube, and I'm using Harlowe.

So; how would I make a button which goes to the last passage the user was on?

Comments

  • You need to also state the version of the story format you are using, as answers can be different for each one. I will assume you are using the latest version of the Twine 2 application (which is v2.1.1) and that you are using the default version of Harlowe (which is v1.2.3)

    You can use the (history: ) macro to obtain an Array containing the names of all the passages already visited, then use the last keyword to access the name of previous passage visited.
    (set: $name to (history:)'s last)
    
    The previous passage was $name.
    
  • greyelf wrote: »
    You need to also state the version of the story format you are using, as answers can be different for each one. I will assume you are using the latest version of the Twine 2 application (which is v2.1.1) and that you are using the default version of Harlowe (which is v1.2.3)

    You can use the (history: ) macro to obtain an Array containing the names of all the passages already visited, then use the last keyword to access the name of previous passage visited.
    (set: $name to (history:)'s last)
    
    The previous passage was $name.
    
    You are correct in that assumption. How would I go about using the variable for making a link, though?
  • Sometimes the best way to determine how to do something is to try it.
    (set: $name to (history:)'s last)
    
    The previous passage was $name.
    
    [[Try 1->$name]]
    
    (link: "Try 2")[(goto: $name)]
    
    (link-goto: "Try 3", $name)
    
    ... you will need to delete the invalid auto-created passage created for the markup-based link.
  • greyelf wrote: »
    Sometimes the best way to determine how to do something is to try it.
    (set: $name to (history:)'s last)
    
    The previous passage was $name.
    
    [[Try 1->$name]]
    
    (link: "Try 2")[(goto: $name)]
    
    (link-goto: "Try 3", $name)
    
    ... you will need to delete the invalid auto-created passage created for the markup-based link.

    Oh. See, I actually DID try that and... assumed it wouldn't work because it created a page for it. >_> Sorry to waste your time!
  • Glyph wrote: »
    assumed it wouldn't work because it created a page for it.
    The auto-create missing passage feature only really understands standard markup links, more advances ones confuses it.

  • edited March 12
    greyelf wrote: »
    Glyph wrote: »
    assumed it wouldn't work because it created a page for it.
    The auto-create missing passage feature only really understands standard markup links, more advances ones confuses it.
    Hello! I return, because this plan actually didn't work out so well.
    It works when you are trying to go back only one page, but consecutive uses of this method creates a loop. If you try to go back two pages, it'll get you stuck between those two pages; as the 'last' page you were on, according to History's Last, is the one you just came from...

    It occurs to me, I don't think there's any way to fix that, actually. I defy you to figure out a way, because as far as I can tell, any attempt to just make a button that goes back to the previous passage will always have this problem.

    There's probably a simple solution and I'm just too dumb to figure it out.
  • edited March 12
    Whoops double post.
  • The (history:) macro provides an array, so it's possible to pull out a specific index of that array to return to. By having navigation increment a variable or something, you could set the back button to go to a specific index in the history instead of just the last passage. That'd be tough to debug, though, depending on how you structure your story.

    Or, depending on your needs, just store the story's current position as a variable and have all back buttons point to that. I'm not exactly sure what you want to have happen, though, so it's tough to make a specific recommendation. I'd be surprised if it was just straight up impossible, but it'll probably take a bit of work and some solid pre planning.
  • Chapel wrote: »
    The (history:) macro provides an array, so it's possible to pull out a specific index of that array to return to. By having navigation increment a variable or something, you could set the back button to go to a specific index in the history instead of just the last passage. That'd be tough to debug, though, depending on how you structure your story.

    Or, depending on your needs, just store the story's current position as a variable and have all back buttons point to that. I'm not exactly sure what you want to have happen, though, so it's tough to make a specific recommendation. I'd be surprised if it was just straight up impossible, but it'll probably take a bit of work and some solid pre planning.

    The best way I can explain the kind of format I'm going for here is... sort of like a Wikipedia article. I'm using Twine to construct something of a universe bible for its wonderful ability to easily organize and link to different passages.

    When something is mentioned, it links to that something one time (and then doesn't link to it again if it's mentioned on the same page, for the sake of style) so that you can easily access it and go read up on it if you want to, and then come back to that page. In theory. You should be able to just go right back to the page you came from without a problem, for the sake of convenience, but... I don't know how the heck to do that.

    This is a serious issue, as my other option is leaving users to seek out certain pages about certain mentioned topics themselves, which can be arduous, making them navigate back to the page they were originally on when they clicked that link through a bunch of other pages, or making a big block of 'Go back to [x page]' links just to cover every possible point of origin, the most convenient but perhaps ugliest method, considering I just want to use backarrows to go back to the previous passage.

    For instance, say I'm writing about a particular place, and I mention a historical event which happened in that place, and link to the page elaborating on that historical event so that I'm not just dropping names without giving the reader a way to know what I'm talking about. They could then click that link to brush up on what that is, then, hopefully, go right back to where they were last.

    Which again, would be simple, were there not multiple paths there - because additionally, there's a 'History' page for that universe, which indexes all of the important historical events which happened in that universe, which is another way you could use to get directly to that page.

    That was a long explanation, but hopefully it frames in detail the system I'm trying to put together here.

  • The technique described in the Basic "return from menu passages" handling for Harlowe thread could be modified to suit your needs.

    Simple mark the sub-passages with a known Passage Tag of your choosing and then modify the (if:) macro to disregard passages with that tag, similar to how it currently disregards passages assigned a menu tag.
  • edited March 13
    greyelf wrote: »
    The technique described in the Basic "return from menu passages" handling for Harlowe thread could be modified to suit your needs.

    Simple mark the sub-passages with a known Passage Tag of your choosing and then modify the (if:) macro to disregard passages with that tag, similar to how it currently disregards passages assigned a menu tag.

    I couldn't discern a way to do what you suggested in a way that would work out. The problem is that there aren't really any sub passages; every passage should be reachable by at least one index, and as such is a 'main' passage.

    For instance:
    History Index -> Historical Event
    Other Index -> Page talking about other topic, mentions historical event -> Historical Event
    It's hard to explain, but I figured out a kind of convoluted way to do what I wanted to.

    I managed to set up a system of variables and links which change depending on where you've been. So...
    Passage title: "History"
    (link:"other topic")[(set: $altroute to "yes")(set: $altrouteback to "History")(goto: "other topic")]
    
    Passage title: "other topic"
    (if: $altroute is "yes")[
    (link: "go back")[(set: $altroute to no)(goto: $altrouteback)]]
    (else:)
    (link: "other altroute page")[(set: $altroute2 to "yes")(set: $altroute2back to "other topic")(goto: "other altroute page")]
    [[go back|related index page]]
    
    Passage title: "other altroute page"
    (if: $altroute is "yes")[
    (if: $altroute2 is "yes")[(link: "go back")[(set: $altroute2 to "no")(goto: $altroute2back)]]
    (else:)[(link: "go back")[(set: $altroute to "no")(goto: $altrouteback)]]]
    (else:)[[[go back|related index page 2]]]
    

    I've only tested this in a limited situation, so I'm not so sure if it could get tangled up easily, but this is the basic idea.
  • edited March 14
    Glyph wrote: »
    Passage title: "History"
    (link:"other topic")[(set: $altroute to "yes")(set: $altrouteback to "History")(goto: "other topic")]
    
    Passage title: "other topic"
    (if: $altroute is "yes")[
    (link: "go back")[(set: $altroute to no)(goto: $altrouteback)]]
    (else:)
    (link: "other altroute page")[(set: $altroute2 to "yes")(set: $altroute2back to "other topic")(goto: "other altroute page")]
    [[go back|related index page]]
    
    Passage title: "other altroute page"
    (if: $altroute is "yes")[
    (if: $altroute2 is "yes")[(link: "go back")[(set: $altroute2 to "no")(goto: $altroute2back)]]
    (else:)[(link: "go back")[(set: $altroute to "no")(goto: $altrouteback)]]]
    (else:)[[[go back|related index page 2]]]
    

    I realized this example is a little wonky. The first other topic page is pretty weird; it doesn't provide a link to the other alt route page for some reason before the (else) where it would show the back button. So, here's a better example of this code:
    Passage title: "Index Topic"
    (link:"other topic")[(set: $altroute to "yes")(set: $altrouteback to "Index Topic")(goto: "other topic")
    
    Passage title: "other topic"
    (if: $altroute is "yes")[(link: "go back")[set: $altroute to no)(goto: $altrouteback)
    (link: "other altroute page")[(set: $altroute2 to "yes")(set: $altroute2back to "other topic")(goto: "other altroute page")]
    (else:)
    [[go back|related index page]]
    
    Passage title: "other altroute page"
    (if: $altroute is "yes")[
    (if: $altroute2 is "yes")[(link: "go back")[(set: $altroute2 to "no")(goto: $altroute2back)]
    (else:)[(link: "go back")[(set: $altroute to "no")(goto: $altrouteback)]]
    (else:)[[[go back|related index page 2]]
    

    However, I'm realizing that this solution is kind of wonky, and there's something far simpler. I realized, instead of using the (history:) array, I could just... make my own array and draw from it. I could make an array of passages which the player has been to, and then draw from the last one for the back button; but these passages are only recorded into the array each time the player clicks an ALTERNATE ROUTE link, and not a link which progresses deeper into a tree of passages normally. I just need to figure out how to set up arrays properly and I feel like that will be a very simple and elegant solution.

    So, I'll reply again once I figure that out, I just had a eureka moment for something that is admittedly very simple and probably basic to you guys. :V
  • edited April 19
    So, I figured out a pretty easy fix here:

    On the first page, you put this:
    (set: $rhistory to (a:))
    

    On subsequent pages, you can do the following with links:
    (link:"don't worry about it, i wanna keep going forward")[(set: $rhistory to $rhistory + (a: "secondlink"))(goto: "fourthlink")]
    

    This adds this page's name to the $rhistory array and proceeds to the next page in the path.

    Every page must have a macro which removes its own name from the $rhistory pool to prevent loops, like so:
    (set: $rhistory to $rhistory - (a: "passagename"))
    

    Then, you can make a back button for pages which recalls the last page like so:
    (link: "Back")[(goto: "$rhistory's last")]
    

    Now, of course, this is a kind of complex fix for something that could simply be cosmetically fixed by a couple of different buttons that take you back to wherever you could have come from, or simply allowing the user to navigate back to where they were, but as a perfectionist that wants to make things look as neat as possible, this is a nice little touch.

    EDIT: It occurs to me that it took me over a month to get back to this thread with this solution. I swear, it didn't take me that long to figure this out. I figured it out in one sitting, I just didn't bother to try again for a long time. :v
Sign In or Register to comment.