[Twine 2][Sugarcube 2] How to create a countdown that runs in the background

Please specify version and format if asking for help, or apply optional tags above:
Twine Version: 2
Story Format: Sugarcube

Hello, I working on a system where the person can brew a potion and go away and explore while it’s being crafted in real-time.

For example, you leave a potion brewing that takes a minute, you can use this minute to go and fight a mob or two and when you come back you can collect it. For a longer potion, you can check and see the time it takes via a meter or countdown.

The biggest problem is I’m not sure how it would run in the background, most things I’ve tried requires the passage to stay open. I have attempted using the javascript Date object but I’m having difficulties making a meter of it. For the meter, I’m using ChapelR’s [The Meter Macro Set], I don’t have any code as all the previous ones were so disorganised that it’s giving me a headache and I feel like I’m trying to do this the wrong way.

Thanks for any help!

Using the JavaScript Date object is definitely the way to go. If you need some help with understanding how to use it, you might want to take a look at the “Time” section of my Twine/SugarCube sample code collection.

That said, for something close to what you want, see the “Countdown Timer” section there for some code which shows you how to track the passage of time and then trigger an action when the time runs out. That code uses the Date object as well.

Hope that helps! :slight_smile: