Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

simple clock

I've made a simple clock for anyone that wants to use it.
It displays a digital time, and can be manipulated by adding or subtracting the variables $hours and $minutes.

I'm not sure if there was a better way of doing this, but I've made a simple clock for anyone that wants to use it.

It could probably be made fancier with font stylings, but serves a purpose as is, so I thought I'd share.
Sample attached.

<<nobr>><<if $hour >12>><<set $hour to ($hour-12)>><<endif>>
<<if $minutes >59 >><<set $hour to ($hour+1)>><<set $minutes to ($minutes - 60)>><<endif>>

the time is <<$hour>>: <<if $minutes is 0>>00<<else>><<$minutes>><<endif>><<endnobr>>

I have also attached a virtually identical 24 hour clock. For reasons I cannot work out, it has a minor glitch when it reaches midnight- the clock on the menu displays correctly ("the time is 0:00") but the same words embedded in the passage don't calculate, and displays as 24:00. (This is fixed on the next click, may matter very little to others, but is stil frustrating)

Comments

  • I've just tested this on Chrome (compiled under Twine 1.4.2) and I haven't had the bug you mentioned with the 24hr clock.  What browser are you testing it on and I'll have a look and see if I get it as well (assuming it's not on Mac or Linux as I don't have access to my Linux machine at the moment). :)
  • Perhaps I'm deluded, but aren't 2400 and 0000 two ways of saying the same time? (which means there really isn't a problem...)

    I think a real clock skips 2400 and goes right to 0000.

    11:59-12:00-12:01
    2359-2400/0000-0001

  • No.  You can't actually have 24:00.  The moment it goes past 24:00 - even by 1 Planck - you're then onto a 25 hour clock (my teacher said to think of it the same way as from the year 1900 onwards it was the 20th century).  It does go from 23:59 as you say, but it will never go to 24:00, but straight to 00:00.  I had an analogue clock in my office in work and it had the 24hr digits around the outside and I know that one said 00 for midnight.
  • Yep, that's why I said it was a minor glitch, Hanon. It only appears that way on the passage (not the menu) and reverts for anything past midnight.
    I compiled using Twine 1.4.1, found the same glitch on IE8 and Chrome. It's functional for my purposes (will be using it in the StoryMenu space).
  • youcancallmedavid wrote:

    I have also attached a virtually identical 24 hour clock. For reasons I cannot work out, it has a minor glitch when it reaches midnight- the clock on the menu displays correctly ("the time is 0:00") but the same words embedded in the passage don't calculate, and displays as 24:00. (This is fixed on the next click, may matter very little to others, but is stil frustrating)


    It's doing that because you have your order of operations wrong.  This is the current 24clock passage:

    <<if $hour24 >23>><<set $hour24 to ($hour24-24)>><<endif>>
    <<if $minutes >59 >><<set $hour24 to ($hour24+1)>><<set $minutes to ($minutes - 60)>><<endif>>

    the 24 hour clock time is <<$hour24>>: <<if $minutes is 0>>00<<else>><<$minutes>><<endif>>
    If you push the hours past 23, it works as intended.  However, if you push the minutes past 23:59, then you see odd behavior you've noticed.  That's because modifying the minutes can alter the hours, but the check to see if the hours have exceeded 23 has already been done by that point, so minute modifications can drive the hours past 23 (which won't be corrected until &lt;&lt;24clock&gt;&gt; is called again).

    Simply swapping the order of the &lt;&lt;if&gt;&gt; statements will fix the issue.  For example:

    <<if $minutes > 59>><<set $hour24 += 1, $minutes -= 60>><<endif>>\
    <<if $hour24 > 23>><<set $hour24 -= 24>><<endif>>\
    The 24 hour clock time is <<print ("0" + $hour24).slice(-2)>>:<<print ("0" + $minutes).slice(-2)>>
Sign In or Register to comment.