Twine Version: 2.3.14
Story Format: Sugarcube
Hello,
I have this great clock/time system running in my project.
/*
Date & Time Widget Setup
*/
<<set
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"
];
/*
Below we have to use the multi-parameter version of the Date
constructor, rather than the date string version, because the
date string version treats a missing timezone offset as UTC.
While there are ways to determine players' timezone offsets,
so they could be added to a date string, it's more convenient
simply to use the multi-parameter constructor.
The point of this is so that you can simply initialize the game
world clock to whatever date and time you wish without having to
worry about the players' timezone offsets, while still ensuring
that they all see the same game world dates and times.
*/
/* params: year , month(0-based) , day , hour(24H) , minute [, second ] */
$gameDate to new Date(2020, 3, 17, 15, 30); /* e.g. Mar 17, 2015 03:24 */
>>
/*
Date & Time Advancement Widget Definitions
*/
/* Adds the specified number of minutes. */
<<widget "addmins">><<nobr>>
<<set _dateOld to $gameDate.toDateString()>>
<<set $gameDate to new Date($gameDate.getTime() + $args[0] * 60000)>>
<<set _date to $gameDate.toDateString()>>
<<if _dateOld != _date>>
<<include "Reset Variables">>
<</if>>
<</nobr>><</widget>>
/* Adds the specified number of hours. */
<<widget "addhours">><<nobr>>
<<set _dateOld to $gameDate.toDateString()>>
<<set $gameDate to new Date($gameDate.getTime() + $args[0] * 3600000)>>
<<set _date to $gameDate.toDateString()>>
<<if _dateOld != _date>>
<<include "Reset Variables">>
<</if>>
<</nobr>><</widget>>
/* Adds the specified number of days. */
<<widget "adddays">><<nobr>>
<<set _dateOld to $gameDate.toDateString()>>
<<set $gameDate to new Date($gameDate.getTime() + $args[0] * 86400000)>>
<<set _date to $gameDate.toDateString()>>
<<if _dateOld != _date>>
<<include "Reset Variables">>
<</if>>
<</nobr>><</widget>>
/*
Date & Time Printing Widget Definitions
*/
/* Prints the current date ("{weekday} {month} {day}, {year}"). */
<<widget "date">>\
<<print String.format("{0} {1} {2}, {3}",
GameDays[$gameDate.getDay()],
GameMonths[$gameDate.getMonth()],
$gameDate.getDate(),
$gameDate.getFullYear()
)>>\
<</widget>>
/* Prints the current time (12H). */
<<widget "time12hr">>\
<<if $gameDate.getHours() eq 0>>\
12\
<<elseif $gameDate.getHours() gt 12>>\
<<print $gameDate.getHours() - 12>>\
<<else>>\
<<print $gameDate.getHours()>>\
<</if>>:\
<<if $gameDate.getMinutes() lt 10>>0<</if>><<print $gameDate.getMinutes()>> \
<<if $gameDate.getHours() gte 12>>PM<<else>>AM<</if>>\
<</widget>>
/* Prints the current time (24H). */
<<widget "time24hr">>\
<<if $gameDate.getHours() lt 10>>0<</if>><<print $gameDate.getHours()>>:\
<<if $gameDate.getMinutes() lt 10>>0<</if>><<print $gameDate.getMinutes()>>\
<</widget>>
/* Prints the current date and time (12H). */
<<widget "datetime">><<date>> <<time12hr>> (<<time24hr>>)<</widget>>
Them, i also have this nice code block below that allow players to save only in a specific tag passage, in that case, “save-enabled”.
/* Save point on specific passage tag save-enable */
$(document).on(':dialogopening', function (ev) {
if (!$("body").hasClass("save-enable")) {
if ($(ev.target).find(".save").length) {
$(ev.target).find(".save").ariaDisabled(true);
}
if ($(ev.target).find(".delete").length) {
$(ev.target).find(".delete").ariaDisabled(true);
}
$('#saves-export').ariaDisabled(true)
$('#saves-clear').ariaDisabled(true)
}
});
So, what i want to achive is a new code block where players can only save in a specific day of the week.
The reason behind it is because i want to create diferent dificculty levels, and how often is possible to save is something that will influence. In a easy mode for example, he can save everytime he is inside his house independent of the day of the week. Regular mode, only inside the player’s house and in specific day of the week. In a Hard mode, only inside the player’s house and only in the first day of the month.
I tried the following knowing that would not work and i will post here to help clarify better what i want.
/* Save point on specific days of the week */
$(document).on(':dialogopening', function (ev) {
if GameDays[$gameDate.getDay()] == "Fri" {
if ($(ev.target).find(".save").length) {
$(ev.target).find(".save").ariaDisabled(true);
}
if ($(ev.target).find(".delete").length) {
$(ev.target).find(".delete").ariaDisabled(true);
}
$('#saves-export').ariaDisabled(true)
$('#saves-clear').ariaDisabled(true)
}
});
Obviously, the if GameDays[$gameDate.getDay()] == “Fri” is wrong and i don’t know how exactly i will target that. Also, wanna wrap everything on a var like, easy mode, regular mode and hard mode.
So that will regulate how often the player can save his game.
Thank you.