Howdy, Stranger!

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

Incorporating the functionality of previous() in Twine 2?

I would like to have a link to the last page containing a certain tag that the user was on. It looks like previous might be the way to do this, but it's not in Twine 2. How should I go about doing this?


  • According to the Harlowe documentation you can use the (history:) macro to determine which passages the reader has visited, and it states that using (history:)'s last will give you the title of the last passage.

    So you should be able to do the following but there seems to be a bug:

    (set: $previous to (history:)'s last)
    For now you will need to assign the array returned by (history:) to a variable first before finding out the last entry:

    (set: $history to (history:))
    (set: $previous to $history's last)
  • Alright, thanks.

    I'd like it to be able to do that, but with a specific tag. ("location", to be precise.) Any idea how to do that?
  • Specifically regarding selecting passages by tag: this is currently not possible, but I'll get to work on it.


    This use-case reveals a serious oversight I'd made regarding (history:): it really shouldn't be an array of strings at all, but an array of datamaps holding passage information - not just the name, but also the tags and possibly the text. There should also be a (passage:) macro, which is used for access into the array. So, (history:) contains "PassageName" would become:

    (if: (history:) contains (passage: "PassageName"))
    which is a bit more verbose, but seems to provide a few readability and type-checking benefits as a result ((passage: "PassgeName") will hurl an error if "PassgeName" is misspelled or isn't a real passage.)

    Thing is, though, I think the best way to implement a search by tag is to implement a functional-lang (filter:) macro like so:

    (filter: item's tags contains "Tag", (history:))'s last
    But, as you can see, I don't have a functional lambda syntax yet, so "item's tags contains "Tag"" is a sheer spitball. By my established notion that hook-brackets denote deferred execution (used in my design for (live:)), it should be:

    (filter: [item's tags contains "Tag"], (history:))'s last
    but I wonder if that's a little confusing - it's not a hook of passage prose, it's just a deferred evaluation, similar to Lisp's single-quote thing. (Then again, I did explicitly reserve the use of square-brackets, taking away JS's array literals, for such an occasion...)
  • Particularly because the PREVIOUS passage one was on is so useful to call when trying to work a HUD or inventory, or whatever, I wonder whether it's worth having some way to do that in a simple way, using it's own macro or inbuild function name.

    For example:
    (goto: (previous:))
    (goto: previous)
    (goto: #previous)

    But I know nothing about coding or what problems, etc. this idea would present.

    Just from the point of view of the user, having an easy way of calling the last passage is quite useful.
Sign In or Register to comment.