0 votes
by (160 points)

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

1 Answer

+1 vote
by (44.7k points)
selected by
 
Best answer

If, for example, you have different passages representing different locations, you could use a <<switch>> macro to determine events there.

<<switch ($day % 7)>>
<<case 0>>
    Everyone is gone. Probably at church.  Ha!
<<case 1>>
    Everyone is hungover and the coffee is burnt.  Must be Monday.
<<case 2>>
    Tuesday staff meeting.
<<case 3>>
    Hump day.  Time to actually get some work done.
<<case 4>>
    No, seriously, get some work done.
<<case 5>>
    Everybody is watching the clock, ready for the weekend.
<<case 6>>
    Woooo!  Saturday morning cartoons!  Oh... wait... they don't show them anymore.
<</switch>>

That's just an example, but it should give you an idea of one way it could be done.

You could put an <<include>> macro inside each of those cases above instead of text if you want to write the content of each of those cases in their own passages.  That would also make it easier to have the same events on some of the days of the week.

You could also use a switch statement like that to list different links based on the time of day.

So, there are lots of ways to do what you want.  You'll have to figure out what way works best for what you're trying to do.

Hope that helps! smiley

by (160 points)
Yep, that works. Thanks!
...