Made with Twine & SugarCube
SugarCube (v2.0.0-beta.4)
So I've been messing around with every type of clock on here for the last week. Most I've figured out, but the base java one I still can't figure out.
<<set $now to new Date(Date.now())>>
<<set $now to new Date("2009-05-08T08:00")>>
now: <<print $now>>
year: <<print $now.getYear()>>
month: <<print $now.getMonth()>>
day: <<print $now.getDay()>>
hours: <<print $now.getHours()>>
minutes: <<print $now.getMinutes()>>
seconds: <<print $now.getSeconds()>>
1) How would I add time manually to this one (+ 15min) or (8 hours) etc.
2) Or to add a set time per click?
3) I'd like to drop the GMT-0500 (Central Daylight Time) from the StoryCaption, but from what I read on the Java sites it seems more involved than its worth. Is there an easy way to not populate it? I know the T in "2009-05-08T08:00" is related to it, is there a letter like X or something to drop it?
I've seriously spent a ridiculous amount of time on something so simple. I think I wrote the 10k of dialogue in less time.
Thanks
Oh, PS: Where do I check these as 'Answered?'
Comments
Secondly, the following is pointlessly calling Date.now(): The Date object's constructor will default to the current date/time if no arguments are given, like so:
Thirdly, I'd suggest setting all dates as UTC and using the UTC methods where applicable, so that all players see the same game world dates and times.
If you mean add a certain number of minutes, or something to that effect, each "turn", then you could do something like I showed above in a predisplay task. For example: If you have passage where you don't want time to pass, you could test for the presence of a tag or tags and skip the time advancement based on that. For example:
No, the T isn't related to it at all. It simply separates the calendar date from the time in the abbreviated ISO8601 date/time string used to construct the Date. It has absolutely no bearing on what's being printed.
You're seeing the TZ info, because <<print $now>> is coercing the Date object in $now to a string, which calls its toString() method. If you don't want to see the TZ, then you have two choices: attempt to remove it from the returned formatted string before printing it or use another method to generate the full date string. I'd probably suggest the latter (as I do in the widget package I'm posting after this).
I'm reposting these widgets here in the hopes someone will find them useful.
The widgets use the JavaScript Date object to provide the inner workings of a Gregorian Calendar (a.k.a. Christian/Western calendar). The initial date should be set in UTC (just set it to the date/time you want, but note that it's in UTC), so that all players see the same game world dates and times (this is also the reason why all of the associated widgets use the UTC methods where applicable).
Gregorian Date & Time Widgets: (goes in a widget tagged passage) The initial game date/time is set in the setup section. Each of the printing widgets can be customized.
Usage, Printing: Usage, Advancing:
But I thought the minutes went in here: Not here...
I'm finding the 'unspoken' things like that, the most difficult to deal with. It's so basic no one talks about it. I never would've thought it was the other way. My brain wants to treat it like math, when I know full well it isn't. I did read that the T / UTC changed the zones and was hoping for an easy fix like X for null.
You're a saint. I REALLY did try to figure it out. I got one of the others to work and advance, but it didn't do days or months. I seriously wasted like 40 hours playing with all these different clocks, but I'm sure a ton of people are going to use this post in the future.
Thanks again Mad, from all of us. I'm really enjoying the hell out of Twine as well as learning to code and all of the helpful people here are the reason why.
Alternatively, if you don't want to fiddle with milliseconds, you could simply set $now to the current time and then use the UTC minute get/set methods I showed above to add the 15 minutes. For example:
so I was experimenting for 2 weeks with this (+15)).
So the advance time thing I have down.
Oh crap! TAGGED widget, not named widget. I never even noticed the 'tag' thing before a second ago.
That's the other piece. I knew I wasn't a moron and that I understood what I was looking at and how it should work. Knew it was something little. I really do think I'm getting this, but little things like that cost me 40 hrs of hair pulling. The whole time I was embarrassed to ask. I feel like we just rebuilt an engine only to have you tell me I was just out of gas, lol.
You're a Saint man. I'll go through everything later and see whats there.
No worries, I tried it there first since it ended in };
It threw an error Cannot read property 'setUTCMinutes' of undefined.
I just tried it again and it worked on the <<print $now>> clock, but not the Widget Clock; until I closed the opened a fresh game, then it threw the error again. (Not planning on using both clocks, just never removed the other one.)
Does it need to be reworded to 'gameMinutes' 'nowMinutes' or something to run with the widgets?
It seems to test fine, but if there is an issue (or a better way) please let me know. Took me awhile to figure it out, hope it saves someone some time.
In your example, there are two ways to look at the store's state:
For example:
What's the shortest way to do 'the alarm clock awakes you up at 8am no matter what time you go to bed (and roll the date forward)? I know there must be a super short way, but I can't hit on it. Resigned myself to doing it in 8-10 lines of increasing the spread and add an hour each line. That's why I figured out the store thing above as a work around for this. If bedtime is between 4-5 add 3 hours. 5-6 add 2 hours, etc.
What is the shorter path O Guru of Sugary Wisdom...
instead of doing all kinds of fancy maths, or is there something I'm missing there? Seemed to work out when I tested it real quick.
made a difference- it doesn't. (In case I had it the 2nd way before).
I guess I could work out a < or > statement that only adds the day if after midnight?
That gets me closer, I think, Eddies. 2 lines of code instead of 10.
Or I could have the player eaten by a Grue or turn into a Gremlin if they don't go to bed before midnight, lol.
Thanks, I'll try it in a minute... <- snicker.
Something like this (if it's not correct tell me). Tested and seems to work fine.
Okay I think that works now...
One step closer to: The TwineCube Clock- The Definitive Edition.
Anyone else using this need it to do anything else- just ask. I'm sure there are other time related issues I haven't need yet.
-Thanks again Eddies!
PS: I've also just realized that I setup the widgets backwards. They should use the local time methods, not the UTC methods, and the time should be specified without a timezone offset. I'll put out a fixed version soon.
The widgets use the JavaScript Date object to provide the inner workings of a Gregorian Calendar (a.k.a. Christian/Western calendar).
Set the initial date to the date/time you want and all players should see the same game world dates and times.
Gregorian Date & Time Widgets: (goes in a widget tagged passage) The initial game date/time is set in the setup section. Each of the printing widgets can be customized.
Usage, Printing: Usage, Advancing:
<<time12hr>> and <<time24hr>>
it should be works now
this is what i get
but when run in twine 2.0 app , the codes are running ok ... is it bug or i'm missing something here ?
PS: I paste Gregorian Date & Time Widgets in a widget tagged passage named widget, and the printing usage in just ordinary passage
Whoops!
First, I'm very sorry to dig up an old thread.
I found that widget (see below) and It seems that I miss something.
I use Twine 2 and sugarcube 2 (I'm also begin in javascript).
I just copy it. Put it in a "passage" tagged "widget".
In a side bar, I add with a CSS code, I want to put in it the date.
So I write in it :
and in the StoryInit
So it shows : "Date: 1/2/2017 08:00:00" and not "Date: Feb 1, 2017 08:00"
Is there a possibility to have the second display ?
Thx.
1. The format of the value you passing to the new Date object you are assigning to the $gameDate variable.
The instructions included in the widget's source code warn about the UTC timezone issue when using a String to initialise the date. Your initialisation should look like the following and ideally you should be modifying the default value set inside the widget code.
eg. replace the $gameDate to new Date(2015, 2, 17, 3, 24); line in the code with. ... to have a date of February 1, 2017 08:00.
2. You are not using the included widgets to display the date and time.
The code includes four widgets/macros (date, time12hr, time24hr, datetime) which should be used to display the game date. Try using the following to achieve the output you want.
So I modify the code (for the date) in the passage (I name it calendar and tag it with "widget")
I write
in my new sidebar (explain by you BTW ^^) : http://twinery.org/forum/discussion/5764/sugarcube-apply-html-code-on-every-passage
it says :
So I think I miss something.
You need to do that so that those macros are available in your story and so you can use them like I did in my examples
yes I do it (see pics attached)
English isn't my native language, so I could misunderstand a sentence. But I think it's good.
Thx for your time.