Variable as Link Target

I have a branching story. I want to use a passage as a simple container which may be reached from any of three or four unsatisfying branches. I then want to give the reader the option of either starting the story anew or returning to the point where they made a sub-optimal choice. I could easily do this by making a separate passage for each of the “return to” pages, but reusing bits of code is always a good thing to do.

The passage to which they might want to return is not going to be the one they just left, so using previous() won’t work. In the code below, I’m trying to set the variable _target to the passage that the reader was in before the passage called “Tell Rob.” But this doesn’t work. Rather than use the content of the variable, Twine creates a new passage called _target.

How can I set it up so that the link for the words “head back” (in the last sentence) will be variable?

<<nobr>><<if previous() is "Tell Rob">>
<<set _target to "More Dosing">>
<</if>>
<</nobr>>
You've steered Jayfer to a not very satisfying point in her life. Would you care to start over and [[try again|Story Start]]? Or would you prefer to [[head back|_target]] to the point where you made the crucial choice?

Okay, I’ve got it working. It’s ugly, but it’s functional. I’m just embedding a clunky if statement in the middle of the paragraph.

You've steered Jayfer to a not very satisfying point in her life. Would you care to start over and [[try again|Story Start]]? Or would you prefer to<<if _target is "More Dosing">> [[head back|More Dosing]]<<elseif _target is "Explanation Part 2">> [[head back|Explanation Part 2]]<</if>> to the point where you made the crucial choice?

From the link markup documentation:

WARNING (TWINE 2): Due to how the Twine 2 automatic passage creation feature currently works, using any TwineScript expression for the Link component will cause a passage named after the expression to be created that will need to be deleted. To avoid this problem, it’s suggested that you use the separate argument form of the <<link>> macro in Twine 2 when you need to use an expression.

As an example:

<<link "head back" _target>><</link>>

Not quite sure this is what you want, but you might want to consider adding the bookmark” special tag to all of the passages you want the player to be able to return to. Then, when the player goes through any passage with a “bookmark” tag, that will enable a “Jump To” button in the navigation bar, which they can use to jump back to any of those bookmarked passages they passed through at any time. You could also use the UI.jumpto() method at any time if you want to open the “Jump To” dialog.

Hope that helps! :grinning:

That’s a cool feature! Thanks for mentioning it. I’m working on a project that’s more of a conventional story than an adventure game, so I’m not sure it would help at the moment. My passages are story events, not locations on a map.