Howdy, Stranger!

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

How to display an option if the player has seen a certain passage?

Is there a macro I can use in Twine 2 to display an option for an action if they have read a particular passage.
For example, in one passage if they choose to pick up a candle, that leads to a confirmation passage with a bit of text about what happens when the candle is collected. How can I macro in an if statement in another passage to light the candle if they've seen the confirmation passage.

If that is a bit vague, or made little sense:

If one passage has been visited, how can I add an option in another passage to display ONLY if they've been to the other passage?

Thanks!

Comments

  • edited June 2015
    You didn't state what Story Format you are using, but if you are using Harlowe, then...

    For this you would use the (history:) macro.

    Using the example you provided, if your confirmation passage of the candle was called "Candle Confirmation", and your other passage (where you want them to go if they have been to Candle Confirmation) is called "Another Passage", then you would use the (if:) statement and (goto:) macro as follows:
    (if: (history:) contains "Candle Confirmation")[(goto: "Another Passage")]
    

    I hope that makes sense and is what you are looking for.
  • Hi Feliwebwork,

    Thanks for your reply!

    That's almost what I'm looking for. I'd like the option to do another action to display, rather than for it to just go to the next passage, if that's possible?

    Thanks again!
  • edited June 2015
    Jskershaw1 wrote: »
    Hi Feliwebwork,

    Thanks for your reply!

    That's almost what I'm looking for. I'd like the option to do another action to display, rather than for it to just go to the next passage, if that's possible?

    Thanks again!

    Yes, it is. Whatever action you want it to do, you put it within the [hook].

    If you want it to just display some text:
    (if: (history:) contains "Candle Confirmation")[This text will be displayed]
    

    If you want to set a variable to something do it like this:
    (if: (history:) contains "Candle Confirmation")[(set: $yourVariable to "string")]
    

    OR if you want the value of the variable to be a number:
    (if: (history:) contains "Candle Confirmation")[(set: $yourVariable to 7)]
    

    It works the same as any (if:) statement.

    Perhaps if you share what action you want we could offer you a specific answer.
  • Thanks bud!

    That's a massive help!

    Cheers!
  • edited August 2015
    I have a similar question but I'm not sure how to do it with the information I'm aware of.

    What if I wanted some text to be displayed based on a previous button choice and other text to be displayed for choosing the same button but with a different title, i.e.

    Candle Confirmation
    This text is different->Candle Confirmation

    In the case above, how would I indicate with the

    (if: (history:) contains "This text is different") ?

    It doesn't work because it's not actually it's own passage, it's only the title to direct to the same passage.

    How could I do that?


  • Using the (history:) macro to test if a passage has been seen should be use sparingly as it needs to search through the whole of a Reader's History to find the answer and this takes slightly longer the more passages the Reader has seen.

    You can use a $variable to remember if something has occurred.

    a. At the start of your story initialize the $variable to a default value like so:
    note: the variable can be named whatever makes sense based on what it is doing.
    (set: $otherCandle to false)
    
    b. Update the $variable if the correct link is selected like so:
    note: this is known a setter link, because the link sets a $variable.
    [[Candle Confirmation]]
    (link: "This text is different")[(set: $otherCandle to true)(goto "Candle Confirmation")]
    
    c. A safer way to do the above is to assign a value to the $variable for both links:
    (link: "Candle Confirmation")[(set: $otherCandle to false)(goto "Candle Confirmation")]
    (link: "This text is different")[(set: $otherCandle to true)(goto "Candle Confirmation")]
    
  • Perhaps I'm still doing something wrong but that didn't perform like I wanted.

    I'd like it to be a normal button and direct the player to a new passage. But depending on which button they choose, different text will start off the passage - followed by the remained of the text that is displayed for either choice.

    So at the top of the said passage, I would need a way to display only the text that should be displayed based on the previous choice.

    If that is confusing here is an example:

    {
    Want some milk?

    No, milk is gross.
    No, thanks. I'm allergic->No, milk is gross.

    In the passage - "No, milk is gross."

    (If: No, milk is gross) All right, milk isn't to everyone liking.
    (if: No, thanks. I'm allergic.) Oh, okay. I didn't know you were allergic.

    But cookies are amazing with milk. At least I think so.

    }

    That's pseudo code for what I want I fathom happening.

    How would I do something like that?
  • Your example using links:

    a. Place the following in one of your passages:
    Want some milk?
    
    (link: "No, milk is gross.")[(set: $allergicToMilk to false)(goto: "No, milk is gross.")]
    (link: "No, thanks. I'm allergic")[(set: $allergicToMilk to true)(goto: "No, milk is gross.")]
    
    b. Place the following in a passage named No, milk is gross.
    (if: $allergicToMilk)[Oh, okay. I didn't know you were allergic.](else:)[All right, milk isn't to everyone liking.]
    
    But cookies are amazing with milk. At least I think so.
    

    Harlowe does not have a built-in button macro.
  • Awesome! Thanks, I'm not sure why I didn't get it to work the first time. That code looks pretty much the same as what you said before.

    One last thing I noticed.

    The line in the story map view no longer appears between the two passages. But when I click on either link, it directs me to the passage normally.
    Is that supposed to happen when writing the code this way?
  • Both the Draw Connections Between Passages and the Auto-Create Missing Passage features only recognize the basic markup links common to all story formats, so link types like Harlowe's (goto:) macro and SugarCube's setter markup link [Next Passage][$var to "value"]] are not supported.
  • Understood. Thanks again!
Sign In or Register to comment.