I am trying to create a survival based game and was wondering if it's possible to create a timer/clock and calendar system to track time uninterrupted throughout the game. Nothing I've tried seems to work and the <<timed>> macros result in "macro does not exist" error. I know how to have it displayed conditionally but I'm not sure how to have the hours displayed at all times.
I have also searched extensively but I find it hard to find any specific information.
Thanks for any help.
Comments
1. You could do a <<timedcontinue>> in a self-referencing widget approach.
StoryInit: <<set $minutes to 0>>
<<widget "clock">>
<<timedcontinue 60s>>
<<set $minutes to $minutes +1>>
<<clock>>
<</widget>>
You'd start the clock running by entering <<clock>> in a starting passage.
You could use conditional logical with something like <<if $minutes gte 60>><<print "First Hour">><<elseif $minutes gte 120>><<print "Second Hour">>.
The only problem with this approach is that while it would require a reloading of the passage to update the <<print>> macro. This may not be an issue if the player is looking through passages fast enough. You could solve this by design, for example by including a "Look at watch" command which would open the time passage, hence always forcing a passage reload when the watch is looked at.
The benefit from this approach is it is simple and as it uses existing SugarCube macros, you can easily tie it into standard variables.
2. You can google "how to create a javascript html stopwatch" and insert the required code into a custom div you make in the <body> section in the SugarCube header.html file in the Twine targets/Sugarcube directory. Then style it with CSS and it will always display in the game.
The possible downside to this approach is you'd need to do some custom coding to link times into any story variables.
At a guess, the non-built-in/optional <<timedcontinue>> macro isn't working because you either didn't download the package for your version of SugarCube (look for the <<replacelink>> macro set under Downloads > Add-ons; for: SC v1 or SC v2) or you installed it incorrectly.
Beyond that, you might find my Gregorian Date & Time Widgets useful—note there are two versions of those widgets in that thread, the one within post I've linked to contains the most up-to-date/correct version.
@TheMadExile I definitely was misusing the macros and you're right, I hadn't downloaded the addons as I was unaware of them. I'm still fairly new to twine and coding in general so it has taken some getting used to but everything is sorted out now. I've tried out your Date and Time widgets as well and they're fantastic, exactly what I was looking for.
Thanks a lot guys.
@TheMadExile Apologies if the answer to this is obvious but I'm not seeing it. Do your Gregorian widgets advance on their own when the game is launched or do they have to be manually configured in each passage?
How and when you call them is up to you, but the short answer is you may do it both ways—i.e. manually, at certain points within your story, and/or automatically, within a special passage like PassageReady.
For example, if you wanted every turn to automatically advance the in-game time ahead one hour (base), you might place something like the following in the PassageReady special passage: Or, to manually jump ahead five in-game days at a specific point in the narrative, you might place something like the following at the top of the passage in question (or via the <<click>> leading to it):
The benefit of that over my original suggestion is that the hours and days would flow naturally on. The calendar would know how many hours had passed from measuring how many minutes.
BTW if you want to include a way to stop the clock, then you'd change it to:
And toggle $clockgo between true and false in passages, before calling <<clock>> again. Eg
<<set $clockgo to false>> to stop.
<<set $clockgo to true>><<clock>> to start.