Making a "go to previous page" feature.

Hey, I just published my game and have gotten feedback that navigating between pages was confusing, so I figured I would make a feature that lets you flip back to the last visited page. I would just use something like [[last page]](page 1) but multiple pages have shared links to each other, so you could end up in a different place than where you came from. My next idea was to make a system where each link to another page has an identifier like [[page3]](lastpage=p2) but I have no idea how to make the other side of that code that actually sends you to the place you came from. Lemme know if you have a solution.

Once again, I am sorry for my unrelenting questions
--constant


I think you could do something like that; but I'd be more tempted to use a little javascript, so you don't have to add the attribute to every link.
Something like:

[[]]:
    var s = squiffy.get("_section");
    var history = squiffy.get("_history") || [];
    if (s == "back") {
        s = history.pop() && history.pop();
        if (s && squiffy.story.sections[s]) {
            squiffy.set("_section", s);
            squiffy.story.section = squiffy.story.sections[s]
        }
    }
    history.push(s);
    squiffy.set("_history", history);

[[back]]:
There's no more 'back' to go. (If there's anything in the history then [[back]] would take you there instead of here)

how do I implement this? sorry


I couldn't get mrangel's method to work either. It looks easy, though. Maybe make it a standard part of a future release? Here's what I do when I need a back option, but I don't like it much. Too wordy.

@start start
[[start]]:
@set back=1

[[start]](1)

[[1]]:
1

[[2]] [[3]] [[back]]({back}, back=1)

[[2]]:

2

[[1]] [[3]] [[back]]({back}, back=2)

[[3]]:

3

[[1]] [[2]] [[back]]({back}, back=3)

OK, I screwed up. The code as shown would run the JS for the page it's going back to, but wouldn't display the text.

This one seems to work:

[[]]:
    var s = squiffy.get("_section");
    var history = squiffy.get("_history") || [];
    if (s == "back") {
        s = history.pop() && history.pop();
        if (s && squiffy.story.sections[s]) {
            squiffy.story.go(s);
            // nerf section to prevent scripts running twice
            //   this may have weird side effects that I've not found
            squiffy.story.section = {passages: squiffy.story.section.passages};
        }
    }
    history.push(s);
    squiffy.set("_history", history);

The pages you have been to are {_history}. Would you like to go [[back]]?

[[back]]:
There's no more 'back' to go. (If there's anything in the history then [[back]] would take you there instead of here)

This topic is now closed. Topics are closed after 180 days of inactivity.

Support

Forums