Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Calendar/Timer in Sugarcube 1.0.34

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.


  • edited July 2016
    Two possible solutions I can see.

    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>>

    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.

  • Thanks for the detailed reply. I set up option 1 the way you described but I'm having issues with the <<timedcontinue>>. It seems none of the timed macros work properly for some reason. They keep returning the same problems. "Error: macro<<timedcontinue>> does not exist. "Error [tw user script 0]:elexists is not defined." I'm not really sure what to do if the macros themselves aren't working.
  • The <<timed>> macro doesn't work because you're using SugarCube v1.x, rather than SugarCube v2.x in which it was introduced.

    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.
  • edited July 2016
    I appreciate all the help guys.

    @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?
  • edited July 2016
    You manually use the <<addmins>>, <<addhours>>, <<adddays>> macros within your story's passages whenever you want the date/time to be changed. The third example in the linked post shows their usage.
  • 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?
    You call the <<addmins>>, <<addhours>>, <<adddays>> widgets to advance the clock and calendar.

    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:
    <<addhours 1>>
    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):
    <<adddays 5>>
  • edited July 2016
    In the context of my example widget above, it'd replace the $minutes variable as in
    <<widget "clock">>
    <<timedcontinue 60s>>
    <<addmins 1>>

    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:
    <<widget "clock">>
    <<timedcontinue 60s>>
    <<addmins 1>>
    <<if $clockgo is true>><<clock>><</if>>

    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.
  • Thanks a lot to you both, I've tried out your suggestions and it works out great.
Sign In or Register to comment.