0 votes
by (730 points)

This one is similar to this question, but it's a little different. Basically, in my story the player gets to explore and can visit four different places. If they have finished visiting all four places, I want to automatically direct them into another passage called Home, which is the ending. Is it possible to do that? I do know that I can use an if statement and then a (go to:) macro, but I have no idea what to put in that if statement.

Sorry if I ask too many questions, I am still pretty new to Twine.

1 Answer

0 votes
by (156k points)
selected by
Best answer

There are a number of ways you can do this, two of them being:

1. Use 4 story variables (one per place) to track if the Reader has visited a particular Passage yet.

1a. Initialise each of the 4 story variables within your story's startup tagged special Passage.

(set: $visitedPassageA to false)
(set: $visitedPassageB to false)
(set: $visitedPassageC to false)
(set: $visitedPassageD to false)

1b. When the Reader views the Passage named "Passage A" then update the $visitedPassageA variable, the same for the other passages and variables.

(set: $visitedPassageA to true)

1c. Use and (if:) macro like the following to determine if all the relevant variables are equal to true

(if: $visitedPassageA and $visitedPassageB and $visitedPassageC and $visitedPassageD)[
	(goto: "Other Passage")


2. Check the array returned by the (history:) macro to determine if it contains the Passage Name of all 4 places.

(set: _visited to (history:))

(if: _visited contains "Passage A" and _visited contains "Passage B" and _visited contains "Passage C" and _visited contains "Passage D")[
	(goto: "Other Passage")

The array return by the (history:) macro grows in length for each and every passage visited, so it can contain the same passage name more than once. Searching though the whole array multiple times for 4 passage names is not an efficient process, the variable based solution has it's own issues because those variables will be stored/saved with each moment within the History sub-system.

by (730 points)
I've been trying to do what you said, but I'm kind of confused about what you meant by "tracking if the reader has visited a passage yet". Did you mean inserting a code that tracks the readers' progress, or something else? I'm a bit of a newbie when it comes to coding, so I apologize if my question is a bit stupid/ignorant.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.