The timer created by the (live:) macro is attached to the current Passage and that timer is destroyed whenever a Passage Transition occurs.
This means it's not possible to have a single countdown related (live:) timer that stays active across multiple passages. So to get around this behavour you will need to create a new countdown related timer within each of the passages you want your countdown to be active in.
The following solution used a $countdownActive variable to track if: the countdown has been activated; or if the countdown is still active. It uses a $countdownCounter variable to track the progression of the countdown, and a $countdownPassage variable to indicate which passage the countdown sents the player to upon completion.
1. Initialise the countdown variables within your project's startup tagged special passage, you will need to change the values of $countdownCounter and $countdownPassage as needed.
(set: $countdownActive to false)
(set: $countdownCounter to 10)
(set: $countdownPassage to "Next Passage")
2. Create a new header tagged special passage in your project to display the countdown counter in. You can name this passage whatever you like, I named mine Countdown Header to indicate the header's purpose.
You can change the message being displayed to whatever you like, however the existance of the two named hooks (countdown and counter) is important as they are targets for later code.
{|countdown)[Countdown: |counter>[$countdownCounter]<br><hr>]}
note: the above example includes a HTML <hr> element to draw a horizontal line between the countdown message and the contents of the current passage. You can safely remove that element from the message if you don't want such an effect, but if you do decide to keep it as part of the message then you will need to place the following CSS within your project's Story Stylesheet area to get around a design flaw in Harlowe's Passage Transition Effect.
hr {
display: inline-block;
width: 100%;
}
3. Create a new footer tagged special passage in your project to contain the code used to run the countdown. Again you can name this passage whatever you like, I used Countdown Footer as my name.
{
<!-- Is the countdown active? -->
(if: $countdownActive)[
<!-- Is there any 'time' left on the countdown counter. -->
(if: $countdownCounter > 0)[
<!-- Refresh and reveal the displayed counter. -->
(replace: ?counter)[$countdownCounter]
(show: ?countdown)
<!-- (Re) start the countdown timer. -->
(live: 1s)[
<!-- Has the countdown been manually deactivated? -->
(if: not $countdownActive)[
(stop:)
]
(else:)[
(set: $countdownCounter to it - 1)
<!-- If 'time' has run out move to the next passage. -->
(if: $countdownCounter <= 0)[
(set: $countdownActive to false)
(go-to: $countdownPassage)
]
<!-- otherwise refresh the displayed counter. -->
(else:)[
(replace: ?counter)[$countdownCounter]
]
]
]
]
<!-- No 'time' left on the counter so stop the countdown. -->
(else:)[
(set: $countdownActive to false)
<!-- Move to the next passage if not already there. -->
(if: (passage:)'s name is not $countdownPassage)[
(go-to: $countdownPassage)
]
]
]
}
note: the above example includes a number of comment lines (the lines that start with <!-- and end with --> ) which try to explain what is happening. These comment lines, as well as any blank lines, can be safely removed.
4. Place the following somewhere in 'Passage 12' to activate the countdown.
(set: $countdownActive to true)
note: you could also change the values of the $countdownCounter and $countdownPassage variables at this time.
5. Place the following somewhere in 'Passage 20' to deactivate/stop the countdown.
(set: $countdownActive to false)
The above solution has been designed so that the countdown can be used multiple times within the same project, however only one 'instance' of the countdown can be active at any one time. To restart the countdown you simply need to reinitialise the relevant variables to the required values within the passage you want to start the countdown in.
eg. If in Passage 100 you want the a new 20 tick countdown that fails to Other Passage then add the following to Passage 100.
(set: $countdownCounter to 20)
(set: $countdownPassage to "Other Passage")
(set: $countdownActive to true)