Howdy, Stranger!

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

Displaying a random passage multiple times

I'm writing a game that picks one of a number of passages and displays it. Clicking a link replaces it with a new passage, and so on. However, right now it takes clicking two links ("window" and "what else") to refresh the passage, and I want to make it just one. (Preferably "window" the first time and "what else?" after that.) Is there a way to do this in Harlowe?

Start Passage:
[[It's road trip time.|Intro]]
(set:$n to 0)
(set:$passages to 4)
(set:$passage to "1")
Intro Passage:
The car rumbles and you look out the [window.]<DisplayNext|
		(click: ?DisplayNext)[(set: $n to $n+1)(set:$passage to (text:(random:1,$passages)))(display: $passage)
		[[What else?|Intro]]]
I have a number of passages titled with the numbers 1-4 that can be displayed here.

Comments

  • I'm a little confused by your question.

    I think the end result you are describing is one where the Reader can click on the same link multiple times and each time they do so the contents of a random child passage is displayed to them. If this is what you want then use one of the following two solutions depending on if you want the Reader to be able to use the Undo button to revisit previously shown random passages.

    1. Reader can't see previous randomly displayed passages:
    This solution uses a (link-repeat: ) macro, a (replace: ) macro and a named hook to achieve the required effect. The solution modifies your existing Intro passage and adds a child passage (named Random Scene) to store the logic code so that the Intro passage does not become messy.

    a. Intro passage:
    |scene>[]The car rumbles and you look out the (link-repeat: "window.")[(display: "Random Scene")]
    
    b. Random Scene passage:
    {
    (set: $n to $n + 1)
    (set: $passage to (text: (random: 1, $passages)))
    (replace: ?scene)[(display: $passage)]
    }
    
    note: You will need to add extra line-breaks to the end of the content of the 1 to 4 passages so that a gap appears between their content and the "The car rumbles and you look out..." text of the Intro passage.

    2. Reader can see previous randomly displayed passages:
    This solution use an (unless: ) macro to conditional show the contents of one of the 1 to 4 passages. The solution modifies your Start passage, your Intro passage and adds a child passage (named Random Scene) to store the logic code so that the Intro passage does not become messy.

    a. Start passage: change the default value of the $passage variable.
    (set: $passage to "")
    
    b. Intro passage:
    {
    (unless: $passage is "")[(display: $passage)]
    The car rumbles and you look out the (link: "window.")[(display: "Random Scene")]
    }
    
    c. Random Scene passage:
    {
    (set: $n to $n + 1)
    (set: $passage to (text:(random: 1, $passages)))
    (goto: "Intro")
    }
    
    note: You will need to add extra line-breaks to the end of the content of the 1 to 4 passages so that a gap appears between their content and the "The car rumbles and you look out..." text of the Intro passage.
  • I ended up using a couple goto: macros instead of sticking everything in the same passage and just copying and pasting the previous text sans link and it worked like a charm. Thanks!
Sign In or Register to comment.