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 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.
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!
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.
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.
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...
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.
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:
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
On the first page, you put this:
On subsequent pages, you can do the following with links:
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:
Then, you can make a back button for pages which recalls the last page like so:
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