0 votes
asked by (120 points)

Hello all!

I'm new to Twine and Harlowe. Here's what I want to accomplish.

I have 4 short passages that I want to take my reader through. In each of these short passages, my reader will have 4 choices to get to the next passage. 

For example:

Reader starts on the 1st Passage.

Reader selects the 4th choice to get to the 2nd passage. Reader arrives to the 2nd passage.

Reader sees a short message about their choice (1st Passage, 4th Choice) and the main text of the 2nd passage.

Reader select the 3rd choice to get to the 3rd passage. Reader arrives to the 3rd passage.

Reader sees a short message about their choices (1st Passage, 4th Choice & 2nd Passage, 3rd Choice) and then the main text of the 3rd passage.

Reader selects the 1st choice to get to the 4th passage. Reader arrives to the 4th passage.

Reader sees a short message about their choices (based on their selection of the 1st Passage, 4th Choice & 2nd Passage, 3rd Choice & 3rd Passage1st Choice). and then the main text of the 4th passage.

 

What is the easiest way to do this?

Thanks in advance!

1 Answer

0 votes
answered by (121k points)

I am going to assume that when you say you want to see a message like the following:
(1st Passage4th Choice & 2nd Passage3rd Choice)

...that you want to track both:
a. the Name of the Passage that the choice was made in.
b. the Link Text of the choice that was selected.

1. You can use an Array story variable to store each of the above two pieces of data, you would initialise this variable within your project's startup tagged special Passage using the (set:) macro and the (a:) macro like so

(set: $choices to (a:))


2. You can use individual Datamap objects to contain each of the pairs (passage and choice) of data, and the code to do this looks something like the following. It uses the (dm:) macro to create the object and the name property of (passage:) macro to obtain the Name of the Current Passage.

(dm: "passage", (passage:)'s name, "choice", "2nd Choice")


3. You would use what is commonly known as Link with Setter (or a Setter Link) to both add the relevant data to the $choices array and to forward the Reader to the next passage. This link type generally consists of a (link:) macro combined with a (set:) macro and a (go-to:) macro, and look something like this

(link: "Link Text")[
	(set: $variable to "value")
	(go-to: "Target Passage")
]


4. Your 1st Passage would combine the information from points 2 & 3 together and look something like the following

This is the (print: (passage:)'s name), please make a choice.

(link: "1st Choice")[
	(set: $choices to it + (a: (dm: "passage", (passage:)'s name, "choice", "1st Choice")))
	(go-to: "2nd Passage")
]

(link: "2nd Choice")[
	(set: $choices to it + (a: (dm: "passage", (passage:)'s name, "choice", "2nd Choice")))
	(go-to: "2nd Passage")
]

(link: "3rd Choice")[
	(set: $choices to it + (a: (dm: "passage", (passage:)'s name, "choice", "3rd Choice")))
	(go-to: "2nd Passage")
]

(link: "4th Choice")[
	(set: $choices to it + (a: (dm: "passage", (passage:)'s name, "choice", "4th Choice")))
	(go-to: "2nd Passage")
]


5. To display the contents of the $choice array you will need to use the (for:) macro to loop through each Datamap contained within it. The following builds a String value ($output) containing containing a formatted representation of each of the pairs of data, it uses a (if:) macro to determine when to add the "&" joiner, and it uses a (replace:) macro to inject this String into a named hook which will exist in the 2nd to 4th Passages.
I named the passage Previous Choices

{
	(set: $output to "")
	(if: $choices's length > 0)[
		(for: each _choice, ...$choices)[
			(if: $output is not "")[
				(set: $output to it + " & ")
			]
			(set: $output to it + (_choice's "passage") + ", " + (_choice's "choice"))
		]
		(replace: ?choices)[$output]
		(set: $output to "")
	]
}


6. Your 2nd Passage would look very similar to your 1st Passage except the Target Passage of the Setter Links would be different, and there would be code to display the Previous Choices. To do the later you will use a (display:) macro to execute the code contained in point 5, and a named hook to receive the the output generated by said code.

Previous Choices: |choices>[(display: "Previous Choices")]

This is the (print: (passage:)'s name), please make a choice.

(link: "1st Choice")[
	(set: $choices to it + (a: (dm: "passage", (passage:)'s name, "choice", "1st Choice")))
	(go-to: "3rd Passage")
]

(link: "2nd Choice")[
	(set: $choices to it + (a: (dm: "passage", (passage:)'s name, "choice", "2nd Choice")))
	(go-to: "3rd Passage")
]

(link: "3rd Choice")[
	(set: $choices to it + (a: (dm: "passage", (passage:)'s name, "choice", "3rd Choice")))
	(go-to: "3rd Passage")
]

(link: "4th Choice")[
	(set: $choices to it + (a: (dm: "passage", (passage:)'s name, "choice", "4th Choice")))
	(go-to: "3rd Passage")
]


7. Your 3rd Passage and 4th Passage would look very similar to your 2nd Passage except the Target Passage of the Setter Links would be different again. So to make each of these passage simply copy the code in point 6 and change the Target Passage referenced by each of the (go-to:) macros to be the relevant new target.

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.
...