Hi there,
I have a game using a time/day system that tracks periods (morning, noon, afternoon, evening, night) and days (Sun through to Sat). The code follows...
This is in a 'widget' passage;
/*
* 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 0>>
<</silently>>\
<</widget>>
This is in StoryInit;
<<set setup.DAYS to ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]>>
<<set setup.PERIODS to ["Morning", "Noon", "Afternoon", "Evening", "Night"]>>
<<set $day to 1>>
<<set $period to 0>>
I also have a 'sleep' passage that uses the <<NextMorning>> macro - it's unavoidable and essential for the game's other functions.
My question is, how can I incorporate the 'days of week' (Mon, Tues, etc) into variables rather than the 'day count' (day 1, day 2, etc)? For example; if the player were to enter an area on a certain day of week a different event would trigger.
Hopefully this makes sense, let me know if not.
Crayman