0 votes
asked by (260 points)
edited by
Kinda a noob here. I wanted to make it where my game displays the year, day and time(hour:min). I want to be able to have so that if the player clicks on a link thats maybe [[cook food]] then make 30 min pass by. Something like that or if the player clicks on a passage [[go to sleep]] then a day goes by and the person wakes up at 7am or for a set amount of hours they want like [[sleep for 3 hours]]. And also is there a way for me to use the current time say its 7pm and a person clicks a passage [[leave house]] can I use an if statement in someway to make it say "Its to late to go outside" I'm using sugarcube, the latest version.

2 Answers

+1 vote
answered by (14.5k points)

You didn't say what story format you're using in your tags, so I'm going to assume you're using SugarCube.

Here's a bunch of code showing how to use the JavaScript Date object in Twine with SugarCube:

<<nobr>>
<<set $CurDate = new Date('August 19, 1975 23:15:30')>>$CurDate<br>
add 15 min<br>
<<set $CurDate = new Date($CurDate.setMinutes($CurDate.getMinutes() + 15))>>$CurDate<br>
<<=$CurDate.toLocaleString("en-US", { weekday: "long", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit" } )>><br>
add 1 day <<set $CurDate.setDate($CurDate.getDate() + 1)>><br>
<<=$CurDate.toLocaleString("en-US", { weekday: "long", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit" } )>><br>
set time <<set $CurDate.setHours(14)>><<set $CurDate.setMinutes(15)>><<set $CurDate.setSeconds(0)>><br>
<<=$CurDate.toLocaleString("en-US", { weekday: "long", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit" } )>><br>
<<set $CurDate = new Date('June 14, 2018 15:30')>>
Current date/time: <<print getDayName($CurDate)>>, $CurDate<br>
<<set $Appointment = clone($CurDate)>>
<<set $Appointment.setDate($Appointment.getDate() + 1)>>
<<set $Appointment.setHours(18)>>
<<set $Appointment.setMinutes(0)>>
<<set $Appointment.setSeconds(0)>>
Raw Appointment date/time: <<print getDayName($Appointment)>>, $Appointment<br>
<<set _timeOptions = { weekday: 'long', year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric' }>>
Formatted Appointment date/time: <<print $Appointment.toLocaleString("en-US", _timeOptions)>><br>
<</nobr>>

Take a look at the JavaScript documentation I linked to above to see other ways you can manipulate the time.

+1 vote
answered by (8.5k points)

Also check out this thread

commented by (260 points)
Thanks man this was very helpfull
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...