Hey!
I'm trying to use If Else statements to display particular passage text depending on the player's previous choices.
Passage C is reached by the player through Choice A or Choice B (this has a longer path).
I want to display certain text is the player reaches Passage C through Choice A and different text if reached through Choice B.
I've looked at tutorials but can't seem to figure out how to phrase my statement to make it work. I'm using Harlowe on Twine 2.
Comments
Two of the ways you can do what you want are:
1. Use a variable to track what option the reader selected.
1a. Initialise the variable in your story's startup tag passage using a (set:) macro.
1b. Update the variable to indicate with option/path was chosen.
eg. In the Choice A passage: ... and in the Choice B passage:
1c. Use an (If:) macro in your Passage C passage to test the current value stored in the variable. ... if there was a third (or more choices) you could also use an (else-if: ) macro.
2. Use the (history: ) macro to determine if a particular passage has been visited by the reader.
eg. Assuming the two passages are named: Choice A and Choice B then you could use code like the following in Passage C
warning: All of the above code was written without using the Twine 2 application and has not been tested, so it may include syntax errors.
::start
::Choice A
::Choice B
::Passage C
I'm still finding these variables a little confusing. I've tried implementing both your suggestions but it's still not performing the way I like - I don't think I've got my head around it.
In Passage 1:
If the Player chooses Choice A, they later get another Passage:
The player can get to this passage through two different branches so I'd like different text to appear in the "Passage with dire consequence" dependent if the Player got there through the original Choice B or the later choice.
I don't really understand what code I'm supposed to put and where - am I using the passage tags or putting it all in the body of the passage? Thanks for your patience!
Do not add white-space (eg. space characters) to either the start or end of the Target Passage Name of a markup based link, doing so causes the automatically created Passage to also have the same white-space in its name.
eg.
I am trying to do something similar, but when I test the code it always goes to my "else" command, even if the variable is set to the "if". This is what my code looks like.
Putting a slash between "if" and "else" caused that to show up with the story text. Thank you for any help.
EDIT: putting "if" and "else" into the same hook causes it to always go to my "if"
Some notes.
1. I changed the second (goto:)'s passage to 'off' because it's usually a terrible idea to include periods and certain other punctuation in passage names.
2. You can place this entire code chunk inside braces ( {} ) to eliminate the new lines as well, instead of using all those back slashes.