Explore all the links before the final link appears

Twine Version: 2.37.3

I am trying to setup the section where the player has to click all the links to expand the text before the final link appears. Am I doing it right, or am I trying to reinvent the wheel?


:: Prologue
/* TODO img: "Hands on the stearing wheel" */
\<<if $explore_before_continue === undefined>>
\<<set $explore_before_continue =  {past: false, present: false, future: false}>>
\<<include Prologue>>
\<<else>>    
The engine hums, straining to push your overloaded car forward. You feel the sweat between your palms and the steering wheel. The road twists through the dense forest. The weight of everything you've packed feels like the physical manifestation of the life you're leaving behind. You glance at the rearview mirror, the reflection of your tired face staring back. You notice the bags under your eyes, but remember that you promised yourself to treat this day as the happy one, not the sad one. A new beginning. You earned it.
<<if $explore_before_continue.past>>

The car swerves slightly as you hit a patch of wet road. Your breath catches, and for a moment, you're back there — back to the panic, the fear. A narrow dark street behind the concert hall. The shape towering above you on that dreadful night. 
You squeeze the steering wheel, grounding yourself in the present. The road straightens, and you let out a shaky breath. It's just a puddle, just another bump in the road.
\<<else>>
<div class="choice">[[Think about the past|Prologue][$explore_before_continue.past = true]]</div>
\<</if>>
<<if $explore_before_continue.present>>

You glance at the clock on the dashboard. It is later than you thought. The sun is dancing on the edge of the horizon, casting long shadows that stretch across the windshield. The forest around you feels heavy. The closer you get, the more you wonder if this new beginning is as promising as you hoped.
\<<else>>
<div class="choice">[[Think about the present|Prologue][$explore_before_continue.present = true]]</div>
\<</if>>
<<if $explore_before_continue.future>>

You imagine your destination, Addison Heights. The small town, much further north than any place you lived before. The quiet streets, the friendly faces. You see yourself settling in, making new friends, finding a sense of peace. The house you were lucky to buy will be the symbol of this new chapter, a place where you can start anew. You smile for a moment focusing on the road ahead.
\<<else>>
<div class="choice">[[Think about the future|Prologue][$explore_before_continue.future = true]]</div>
\<</if>>
\<<set _exit_link = false>>
<<script>>
State.temporary.exit_link = Object.values(State.variables.explore_before_continue).every( v => v === true)
<</script>>
<<if _exit_link>>    
<div class="choice">[[Keep driving|Prologue Accident][$explore_before_continue = undefined]]</div>
<</if>>
<</if>>

Is there a way to do it simpler and nicer? Without keeping track of all the paragraphs set to false/true?

Is the $explore_before_continue unset properly after I go to the next passage?

you might like the visited() property. on the central page (where all the links are), have an <<if>> that checks if you’ve visited the first three passages and shows the link if you have.

though your way works fine, coincidentally it’s what I did for my own game where the protag is meant to think about stuff before moving on. not sure why the <<script>> is there though.

1 Like

Using <<linkreplace>> and <<replace>> could simplify the logic.

Would something like this work? There is some repetition due to the condition evaluation needing to be in every fold-out paragraph, but it’s not that bad.

<<set _exitTexts = ["", "[[Keep Driving]]"] >>\
The engine hums, straining to push your overloaded car forward. You feel the sweat between your palms and the steering wheel. The road twists through the dense forest. The weight of everything you've packed feels like the physical manifestation of the life you're leaving behind. You glance at the rearview mirror, the reflection of your tired face staring back. You notice the bags under your eyes, but remember that you promised yourself to treat this day as the happy one, not the sad one. A new beginning. You earned it.

<<linkreplace "Think about the past">>The car swerves slightly as you hit a patch of wet road. Your breath catches, and for a moment, you're back there — back to the panic, the fear. A narrow dark street behind the concert hall. The shape towering above you on that dreadful night. 
You squeeze the steering wheel, grounding yourself in the present. The road straightens, and you let out a shaky breath. It's just a puddle, just another bump in the road.
<<set _past to true>>\
<<replace "#exitText">><<print _exitTexts[Number(!!_past and !!_present and !!_future)]>><</replace>>\
<</linkreplace>>
<<linkreplace "Think about the present">>You glance at the clock on the dashboard. It is later than you thought. The sun is dancing on the edge of the horizon, casting long shadows that stretch across the windshield. The forest around you feels heavy. The closer you get, the more you wonder if this new beginning is as promising as you hoped.
<<set _present to true>>\
<<replace "#exitText">><<print _exitTexts[Number(!!_past and !!_present and !!_future)]>><</replace>>\
<</linkreplace>>
<<linkreplace "Think about the future">>You imagine your destination, Addison Heights. The small town, much further north than any place you lived before. The quiet streets, the friendly faces. You see yourself settling in, making new friends, finding a sense of peace. The house you were lucky to buy will be the symbol of this new chapter, a place where you can start anew. You smile for a moment focusing on the road ahead.
<<set _future to true>>\
<<replace "#exitText">><<print _exitTexts[Number(!!_past and !!_present and !!_future)]>><</replace>>\
<</linkreplace>>
<span id="exitText"></span>
1 Like

This one follows the same reentrant approach as your example, but it’s a bit simpler. It still takes advantage that true/false conditions converted to numbers are 1 or 0.

<<set $prologue to $prologue or {past:false,present:false,future:false} >>\
The engine hums, straining to push your overloaded car forward. You feel the sweat between your palms and the steering wheel. The road twists through the dense forest. The weight of everything you've packed feels like the physical manifestation of the life you're leaving behind. You glance at the rearview mirror, the reflection of your tired face staring back. You notice the bags under your eyes, but remember that you promised yourself to treat this day as the happy one, not the sad one. A new beginning. You earned it.

<<if $prologue.past>>The car swerves slightly as you hit a patch of wet road. Your breath catches, and for a moment, you're back there — back to the panic, the fear. A narrow dark street behind the concert hall. The shape towering above you on that dreadful night. 
You squeeze the steering wheel, grounding yourself in the present. The road straightens, and you let out a shaky breath. It's just a puddle, just another bump in the road.

<<else>>\
[[Think about the past->Prologue][$prologue.past to true]]
<</if>>\
<<if $prologue.present>>You glance at the clock on the dashboard. It is later than you thought. The sun is dancing on the edge of the horizon, casting long shadows that stretch across the windshield. The forest around you feels heavy. The closer you get, the more you wonder if this new beginning is as promising as you hoped.

<<else>>\
[[Think about the present->Prologue][$prologue.present to true]]
<</if>>\
<<if $prologue.future>>You imagine your destination, Addison Heights. The small town, much further north than any place you lived before. The quiet streets, the friendly faces. You see yourself settling in, making new friends, finding a sense of peace. The house you were lucky to buy will be the symbol of this new chapter, a place where you can start anew. You smile for a moment focusing on the road ahead.

<<else>>\
[[Think about the future->Prologue][$prologue.future to true]]
<</if>>\
<<print ["", "[[Keep Driving]]"][Number($prologue.past and $prologue.present and $prologue.future)] >>

If you don’t mind having recursive links, simply linking back to the page before might work.

If the specific effect you want is one where the game “remembers you’re snowgraves” though, I don’t know much about that. I know a little bit about how to do something similar in Inform 7. However, I haven’t touched twine in probably a year at this point.

Thank you.

That very first and very last line are really neat. I will be using those.

I didn’t know print could output something like that.

2 Likes