The following shows how to setup a very basic Block based time system.
1. Place the following within your StoryInit special passage.
It defines the names of the "Days of the Week" and of the "Time Periods in a Day" on the special setup variable so that they aren't added to the story's saves. It also defines the $day and $period story variables which are used to track the current day and period respectively.
/% The names of the Days of the Week. %/
<<set setup.DAYS to ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]>>
/% The names of the Time Periods of a Day. %/
<<set setup.PERIODS to ["Asleep", "Morning", "Noon", "Afternoon", "Evening", "Night"]>>
/% The current Game Day: Monday. %/
<<set $day to 1>>
/% The current Time Period: Morning. %/
<<set $period to 1>>
NOTE: The comments within the above (and proceeding) code examples can be safely removed, they are only there to try and add some clarity to what is happening.
2. Place the following within a widget tagged Passage.
(The name of the passage isn't important and can be whatever you like, I named mine StoryWidgets)
/*
* <<now>>
*
* Displays the current Day of Week, Period of Day and Day Number.
*/
<<widget "now">>
\It is <<print setup.DAYS[$day % 7]>>, <<print setup.PERIODS[$period]>>, Day $day.
<</widget>>
/*
* <<AdvancePeriod [number of periods]>>
*
* Advance current Time Period by a set number of periods, if no number
* if pass to widget then current Time Period is advanced by 1 unit.
*
* <<AdvancePeriod>> Advances time period by 1 unit.
* <<AdvancePeriod 1>> Advances time period by 1 unit.
* <<AdvancePeriod 2>> Advances time period by 2 units.
*
* If the current day's time boundary is exceeded then the Day Number
* will also be updated.
*/
<<widget "AdvancePeriod">>
\<<silently>>
<<set _offset to 1>>
<<set _periodsInDay to setup.PERIODS.length>>
<<if $args.length > 0>>
<<set _offset to $args[0]>>
<</if>>
<<set $period += _offset>>
/% Update the Day Number as necessary. %/
<<if $period >= _periodsInDay>>
<<set $day += Math.trunc($period / _periodsInDay)>>
<<set $period to ($period % _periodsInDay)>>
<</if>>
<</silently>>\
<</widget>>
/*
* <<NextMorning>>
*
* Advances the current Time Period to the Morning of the next day.
*/
<<widget "NextMorning">>
\<<silently>>
/% Increament the Day Number by 1 unit. %/
<<set $day += 1>>
/%
Set the current Time Period to the index of the
"Morning" element of setup.PERIODS array.
%/
<<set $period to 1>>
<</silently>>\
<</widget>>
...the following is a simple example of how to use the above widgets.
@@#now;<<now>>@@
<<link "Advance period by 1 unit">>
<<AdvancePeriod>>
<<replace "#now">><<now>><</replace>>
<</link>>
<<link "Advance period by 3 units">>
<<AdvancePeriod 3>>
<<replace "#now">><<now>><</replace>>
<</link>>
<<link "Advance period by 10 units">>
<<AdvancePeriod 10>>
<<replace "#now">><<now>><</replace>>
<</link>>
You will of noted that the PERIODS array defined in point 1 includes an extra period at the start of the day named "Asleep". I did this so that you can have events that occur while the Main Character is asleep (eg. Dreams, etc...), which would otherwise between the last period of a day "Night" when they go to bed and the start of the next day "Morning" when they wake up. You can obviously rename that period (or any other) to whatever makes sense to you.