0 votes
by (120 points)
I'm using Twine 2.3.1, Harlowe 2.1.0.

I have made a universal timer using the following code in a special passage tagged "footer".


(if: $time is "limited")[You have (css: "color: red")[|amount>[$counter]] seconds till detonation.

(live: 1s)[
(set: $counter to it - 1)
(if: $counter is 0)[(stop:)(go-to: "Detonation")]
(replace: ?amount)[$counter]
] ]

The timer works perfectly across all passages, activated when the player reaches a passage with (set: $time to "limited") included in the code. However, my (if: $counter is 0)[(stop:)(go-to: "Detonation")] code doesn't seem to work. It takes the player to the right "Detonation" passage, but the counter remains visible and continues counting into negative numbers. Any ideas?

I have tried (if: $counter is 0)[(stop:)(set: $time to "finished")(go-to: "Detonation")], which doesn't give me an error message, but still causes the same issue.

1 Answer

+1 vote
by (68.4k points)

You're not stopping the timer from being created in the first place if $counter has already reached 0.  I'd also suggest changing the (if:) check within the timer to trigger on less-than-or-equal to 0, rather than simply equal to 0 as you have now.

Try something like the following:

(if: $time is "limited")[You have (css: "color: red")[|amount>[$counter]] seconds till detonation.

(if: $counter > 0)[(live: 1s)[
(set: $counter to it - 1)
(replace: ?amount)[$counter]
(if: $counter <= 0)[(stop:)(go-to: "Detonation")]
] ] ]


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.