Display text depending on previous choices (SugarCube)

Twine Version: 2.3.14
Story Format: SugarCube 2.34.1

Hello! I am on SugarCube, how do I display a especific text depending on player’s previous choices?

For example. There is a passage where the player can choose to do a certain action or not. I want to, in a bunch of passages later, display a text for those who choose to do the action, and a different text for thoose who didnt, both of these text in the same passage.

hypothetical example:

Passage A:
blah blah blah
[[Kiss Mary]]
[[Push Mary]]

Later in the story:

Passage G:
blah blah blah
if player has chosen to kiss Mary: display text 1
if player has chosen to push Mary: display text 2
blah blah blah

English is not my native language, i hope i made myself clear.

Please use the toolbar’s Preformatted Text </> option when including code examples in your comments, it makes them easier to read/copy and stops the forum’s software converting valid Standard quotes into invalid Typographical (curvy) quotes.

The two most common methods used to achieve the outcome you want are:

1: Using the hasVisited() function to determine if a specific Passage has been ‘visited’ during the current story playthrough History.

The following is a modified version of your Passage G that uses that function combined with one of the <<if>> family of macros to determine which content to display.

note: You didn’t specific if there was to visit this Passage without making the ‘choice’ so I have used an <<elseif>> macro instead of an <<else>> macro to determine if the 2nd line of text should be shown.

blah blah blah
<<if hasVisited("Kiss Mary")>>display text 1
<<elseif hasVisited("Push Mary")>>display text 2
<</if>>\
blah blah blah

2: Using a Story Variable to track which ‘choice’ was selected.

Currently in your example there are only two actions you can do to Mary (eg. ‘kiss’ & ‘push’), but it is unclear if that choice is mandatory or if there is a situation where neither action occurs. For this reason I will use a String variable to indicate which action occurred, and defaults this variable to “unknown” within the project’s StoryInit special Passage…

note: The following example uses TWEE Notation to allow it to contain the contents of multiple Passages.

:: StoryInit
<<set $MaryAction to "unknown">>

:: Start
[[Passage A]]

:: Passage A
blah blah blah
[[Kiss Mary][$MaryAction to "kiss"]]
[[Push Mary][$MaryAction to "push"]]

:: Kiss Mary
Kiss Mary selected.
[[Passage G]]

:: Push Mary
Push Mary selected.
[[Passage G]]

:: Passage G
blah blah blah
<<if $MaryAction is "kiss">>display text 1
<<elseif $MaryAction is "push">>display text 2
<</if>>\
blah blah blah
1 Like

Thank you so much! I have a question:

Question: In your first solution, using the “visited function” let’s say the player chooses “push marcy”, but then regrets it, push “go back” and chooses “kiss mary” instead. That is, They visited the passage “push mary”, went back, then went in the “kiss mary” path.

Later, when the player arrives at passage G, Will the game remember that the player definitive choice was to kiss and then the game will display only text 1?

or will the game assume that the player choose both of these options (kiss and push) and then display text 1 and 2?

Sorry if this is confusing, I dont know how to formulate this question in a easy way to understand. Im only asking this because my friend is a really indecisive person and always select “go back” when she regrets the decision.

And Sorry if this question is dumb, I am REALLY new to twine. Thank you again for helping me!

If by 'push “go back”" you mean they used the navigation Undo link to wind back History so that that specific Passage Transition never occurred, then the History system that the hasVisited() function searches through would not contain that specific Passage visit because it never happened.

If by 'push “go back”" you mean something else then the answer would depend on what you meant.