Please specify version and format if asking for help, or apply optional tags above:
Twine Version: 2.3.9
Story Format: Sugarcube 2.33.2
Using another thread I was able to create a basic calendaring system that is working nicely tracking the date and weekday/weekend. To add a bit of fictitious realism I wanted to have one random holiday day per month, with two months having static dates: with one in February; and two in December.
To prototype it, I’ve got everything in one passage. Once I’ve got it working it will be put into appropriate passages.
There may be a better way to do this, but this is what I was able to manage using the SugarCube documentation and my limited skills. Currently there is no weekday/weekend checking, that will be added once I get the below working.
I’ve got everything but two parts working:
- The created dates for the random months are not working. The month, max days in month, and created date all work, but when I try to put them into a date format they all display “1/1/2020, 0:00:00 AM”. The two static months work perfectly and the dates are valid. The only possible thing I can think of is that _months is a two-digit number and not a long month. Could that be it? If so, I’ll need to map that to a long month.
- The attempt to push the value to the array doesn’t seem to do anything. The second FOR just prints out ‘$holidays[_i]’ 13 times.
Any advice on what I’ve done wrong?
<<set _months to 1>>
<<set $holidays to []>>
<<for _months; _months <= 12; _months++>>
<<if _months == 2>>\
<<set _tempdate to new Date('February 14, 2020')>>\
$holidays.push(_tempdate)
<<elseif _months == 12>>\
<<set _tempdate to new Date('December 25, 2020')>>\
$holidays.push(_tempdate)
<<set _tempdate to new Date('December 26, 2020')>>\
$holidays.push("_tempdate")
<<else>>\
<!-- get number of days in month -->
<<set _tempdate to new Date(2020, _months, 0).getDate()>>\
<!-- get random date between 1 and max days in month -->
<<set _temprandom to random(1, _tempdate)>>\
<<set _tempdate to new Date('_months _temprandom, 2020')>>\
$holidays.push("_tempdate")
<</if>>\
<</for>>\
<<for _i = 0; _i <=13; _i++>>
<<print _i + 1>>. $holidays[_i]
<</for>>
Thanks!
Edit: removed pointless lines in the two static month, setting the _temprandom value which wasn’t used.