Repeating Event Help

Using Sugar Cube 2.28.2 and the latest release of Twine. I’m new to twine so I’ve been piecing things together from random sources. What I’m trying to do is have a repeated event on every Friday in game after you’ve talked to Ron. I got the concept of <<if $TalkedToRon == True/False>> down, but the date is messing me up. I’ve copy and pasted this block of code. I can’t find the page i got it from exactly.

This is the time system I have in place. I’m not sure what part of this code specifically is talking about Monday-Sunday so i’m not sure what to put. I’ve been fiddling around with it for a few hours now and i couldn’t find anything online.

	Date & Time Widget Setup
	/* This must be set to whatever the initial game date/time should be. */
	$gameDate to new Date("2019-01-01T01:04Z"); /* Must use UTC time. */
	window.GameDays to [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
	window.GameMonths to [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"

	Date & Time Advancement Widget Definitions
/* Adds the specified number of minutes. */
<<widget "addmins">>\
<<run $gameDate.setUTCMinutes($gameDate.getUTCMinutes() + $args[0])>>\

/* Adds the specified number of hours. */
<<widget "addhours">>\
<<run $gameDate.setUTCHours($gameDate.getUTCHours() + $args[0])>>\

/* Adds the specified number of days. */
<<widget "adddays">>\
<<run $gameDate.setUTCHours($gameDate.getUTCHours() + $args[0] * 24)>>\

	Date & Time Printing Widget Definitions
/* Prints the current date ("{weekday} {month} {day}, {year}"). */
<<widget "date">>\
<<print String.format("{0} {1} {2}, {3}",

/* Prints the current time (12H). */
<<widget "time12h">>\
<<if $gameDate.getUTCHours() eq 0>>\
<<elseif $gameDate.getUTCHours() gt 12>>\
<<print $gameDate.getUTCHours() - 12>>\
<<print $gameDate.getUTCHours()>>\
<<if $gameDate.getUTCMinutes() lt 10>>0<</if>><<print $gameDate.getUTCMinutes()>> \
<<if $gameDate.getUTCHours() gte 12>>PM<<else>>AM<</if>>\

/* Prints the current time (24H). */
<<widget "time24h">>\
<<if $gameDate.getUTCHours() lt 10>>0<</if>><<print $gameDate.getUTCHours()>>:\
<<if $gameDate.getUTCMinutes() lt 10>>0<</if>><<print $gameDate.getUTCMinutes()>>\

/* Prints the current date and time (12H). */
<<widget "datetime">><<date>> <<time12h>><</widget>>

The latest release of Twine 2 (v2.3.5) comes with SugarCube v2.30.0, so… yeah.

Anyway. Assuming you’re advancing the date via the included widgets, you could do something like the following to check that the current day of the week is Friday:

<<if $TalkedToRon and $gameDate.getDay() is 5>>

The <Date>.getDay() method returns the day of the week as a zero-based integer, starting with Sunday—i.e., Sunday–Saturday: 0–6.

Alternatively. You could use the GameDays array to map the integer day of the week to a string. For example:

<<if $TalkedToRon and GameDays[$gameDate.getDay()] is "Fri">>

I’d probably just stick with the returned integer value, but the string may be easier for you to grok.

Yep, forgot i got twine like last month and just started using it here recently, so it’s not as up to date as i thought, sorry. And wow, that was simple… Thank you!!!

Made a small edit to my previous post to add another example and some additional information.

1 Like

Since you’re using the JavaScript Date object with SugarCube, you might want to take a look at the “Time” section of my Twine/SugarCube sample code collection, since it shows you a much easier way to display times and dates, and other tips and tricks for working with the Date object.

Enjoy! :slight_smile:

1 Like