[Macros] Complete Date/Time macro set relased

I’m finally happy to announce the official release of my custom time system macros for Sugarcube, which I have creatively called DATESYSTEM The Datesystem macros are intended to provide an entire drop-in date/time system, capable of imitating a Gregorian calendar, or supporting an entirely custom date/time system. It offers a variety of macros, and corresponding JS functions.

These macros are intended for anyone who’d like a complex date/time system in their Twine/Sugarcube game, but don’t want to write their own. Need more features? Let me know and I’ll be happy to look at adding them.

Features

* Fully customisable date system (min/hour/day/month/year lengths) - defaults to Gregorian
* Custom month names
* Custom day names
* Custom time unit names
* Leap year support
* Set to real-world time
* Sends custom event when time changes
* Supports multiple time systems in one game
* Time tracked in a single story variable for each time system

Macros

* <<date>> outputs a formatted date or time, with full format control
* <<dateset>> sets the date/time
* <<dateto>> sets to an absolute time
* <<dateadd>> moves the time forward by some unit(s)
* <<datesubtract>> moves the time backwards by some unit(s)
* <<datenext>> moves the time forward to the next minute/hour/day/year (i.e discards fractions of that time unit)
* <<datereset>> sets the new base time and resets the time counter
* <<dateperiod>> outputs a time as a period/duration
* <<dateticker>> creates a ticking clock with 1s precision
* <<datesetup>> handles the setup of the date system

Functions

* Functional versions of every macro
* dateCompare() function to compare parts of dates
6 Likes

Thanks! This looks useful.

I’ve never wanted to use a real-time like time system in my games, but people ask for it all the time, so I thought that instead of always explaining roughly how it works, I could just make a library …

2 Likes

I’ve never wanted to use a real-time like time system in my games, but people ask for it all the time

I was considering making a tamagotchi-style pumpkin-raising game for Ectocomp one year.

I didn’t have to do it anyway at that point, but I was considering whether the best way to do it was to use real time (I think you can get the computer’s date and time with js) or with a turn-based time system (like yours).

Maybe this year…

Edit: I see at the end of the readme and the points above that you can get the real date? That’s the best of both worlds.

Yes, you can set the system to initialise or update to the real date when you want, with the getRealDate() function.

1 Like

I’ve added a new macro to this set, <<at>>

Syntax <<at "date string or number" [system-id]>>[code to run]<</at>>

The <<at>> macro allows you to run code dynamically when the game time reaches a certain value. You could use this to put a notification on screen, trigger an event, or interrupt gameplay to go to a new passage. The event is triggered by the :dateupdated event (see below), which means that any of the date changing macros (including the clock created by <<dateticker>>) can trigger it.

The first argument to the macro should either be a date string (like “2000y 10mo 1d”) or a number representing the time (like you might get from $time + 60). As soon as the current $time reaches or passes that value, the code inside the <<at>> will be run.

Example

<<at "2000y 1mo 1d 4h">>
    <<run alert("Time up!")>>
<</at>>

The code inside the <<at>> will use the value of story and temporary variables at the time it runs, rather than at the time it was created. If you want it to use the values when it was created, wrap it in a <<capture>> macro, as you would do for a <<link>>.

Example

:: PassageOne
<<dateset "2000y 1mo 1d">>
<<set _name = "Hituro">>
<<capture _name>>
    <<at "2000y 1mo 1d 4h">>
        <<run alert(`Hello ${_name}`)>>
    <</at>>
<</capture>>
<<link [[Go to 4am|PassageTwo]]>><<dateadd "3h">><</link>>

:: PassageTwo
<<set _name = "Bob">>

When you go to PassageTwo the alert will show “Hello Hituro” because _name was captured when the <<at>> was run. Without the <<capture>> it would show “Hello Bob” instead.