Just that: has anyone implemented wall clock time in Dialog so far?
As in, puzzles involving times like 3:30 or 6:45? Or measuring the actual time that the game is being played?
(global variable (master timer 540))
(global variable (hours 9))
(global variable (minutes 0))
(on every tick)
(master timer $Time)
($Time plus 1 into $NewTime)
(if) ($NewTime modulo 60 into 0) (then)
(now) (minutes 0)
($NewTime divided by 60 into $H)
(if) ($H > 12) (then)
($H minus 12 into $NewHours)
(now) (hours $NewHours)
(else)
(now) (hours $H)
(endif)
(else)
($NewTime modulo 60 into $M)
(now) (minutes $M)
($NewTime minus $M into $NewNewTime)
($NewNewTime divided by 60 into $H)
(if) ($H > 12) (then)
($H minus 12 into $NewHours)
(now) (hours $NewHours)
(else)
(now) (hours $H)
(endif)
(endif)
(now) (master timer $NewTime)
(redraw status bar)
(status bar @status) {
(if) ~(endgame) (then) (time headline) (else) (endgame headline) (endif)
(status headline)
}
(time headline)
(div @score) {
(hours $Hours)
(minutes $Minutes)
(master timer $Timer)
$Hours (no space):(no space)
(if) ($Minutes = 0) (then)
00
(elseif) ($Minutes < 10) (then)
0 (no space)$Minutes
(else)
$Minutes
(endif)
(if) ($Timer < 720) (then) AM (else) PM (endif)
}
Cool, yes, that! Did you just write that here or was it already floating around?
did i just write that? HA! god no. i wrote it a while back and, looking at it now, i can barely follow it. i do remember that it was a tougher task than i had initially anticipated.
Nice! I might keep only a single global variable for the total time; keeping three separate ones increases the risk of them getting out of sync. But since there’s only a single rule that modifies them, that risk is still pretty small.
I presume that this is for game time, not real time? Here’s a longer version that’s been lying around as part of my current WIP for several years:
%% time.dg
%% Basic handling of time. Day of week not supported for now.
(extension version) Time and date v0.1, by Susan Davis (line)
(global variable (current time $)) %% time of day, in minutes from midnight
(global variable (current date [$ $ $])) %% [day, month, year]
(interface (current time into $>Timestamp))
(interface (set time $<Timestamp))
(interface (clock time))
(interface (military time))
(interface (short date))
(interface (full date))
(interface (nato time))
(interface (elapse $<Num minutes))
(interface (elapse $<Num hours))
(interface (elapse $<Num days))
%%----------------------------------------------------------------------
($Hours hours $Minutes minutes)
(current time $Time)
($Time divided by 60 into $Hours)
($Time modulo 60 into $Minutes)
(leading zero $Num)
(if) ($Num < 10) (then)
0 (no space)
(endif)
$Num
(clock time)
($H hours $Minutes minutes)
($H modulo 12 into $Hr)
(if) ($Hr = 0) (then)
($Hours = 12)
(else)
($Hr = $Hours)
(endif)
$Hours : (no space)
(leading zero $Minutes)
(if) ($H > 11) (then)
PM
(else)
AM
(endif)
(military time)
($H hours $M minutes)
(leading zero $H) : (leading zero $M)
%% negate to get D-M-Y dates
(using north american dates)
(short date)
(current date [$D $M $Y])
(if) (using north american dates) (then)
$M \/ $D \/ $Y
(else)
$D - $M - $Y
(endif)
(month for 1) January
(month for 2) February
(month for 3) March
(month for 4) April
(month for 5) May
(month for 6) June
(month for 7) July
(month for 8) August
(month for 9) September
(month for 10) October
(month for 11) November
(month for 12) December
(full date)
(current date [$D $M $Y])
(if) (using north american dates) (then)
(month for $M) $D, $Y
(else)
$D (month for $M), $Y
(endif)
(mon for 1) Jan
(mon for 2) Feb
(mon for 3) Mar
(mon for 4) Apr
(mon for 5) May
(mon for 6) Jun
(mon for 7) Jul
(mon for 8) Aug
(mon for 9) Sep
(mon for 10) Oct
(mon for 11) Nov
(mon for 12) Dec
(nato time)
($H hours $M minutes)
(current date [$D $Month $Y])
(leading zero $D) (no space)
(leading zero $H) (no space)
(leading zero $M)
(mon for $Month)
($Y modulo 100 into $YY)
(leading zero $YY)
(set time $Timestamp)
([$Time | $Date] = $Timestamp)
(now) (current time $Time)
(now) (current date $Date)
(elapse $H hours)
($H times 60 into $Minutes)
(elapse $Minutes minutes)
(elapse $D days)
(if) ($D > 11) (then)
($D minus 11 into $Additional)
(elapse $Additional days)
($Days = 11)
(else)
($Days = $D)
(endif)
($Days times 1440 into $Minutes)
(elapse $Minutes minutes)
%% hook for handling elapsing past the end of a month, and having to care
%% about calendars and leap years; by default, we don't bother with this,
%% to save game size
(normalize date)
(elapse $Num minutes)
(current time $Time)
(current date [$D $M $Y])
($Num divided by 1440 into $Days)
($Num modulo 1440 into $Minutes)
($D plus $Days into $Date)
($Time plus $Minutes into $Ticks)
(if) ($Ticks > 1439) (then)
($Ticks minus 1440 into $NewTime)
($Date plus 1 into $NewDate)
(else)
($NewTime = $Ticks)
($NewDate = $Date)
(endif)
(set time [$NewTime $NewDate $M $Y])
(normalize date)
(late on every tick) (elapse 1 minutes)
…and FWIW, here are the unit tests (using testrunner.dg, which I posted elsewhere):
%% dgdebug -q time-tests.dg time.dg testrunner.dg stdlib.dg
(list of tests [
#hours-minutes
#hours-minutes-zero
#hours-minutes-after-midnight
#leading-zero-zero
#leading-zero-one
#leading-zero-nine
#leading-zero-ten
#clock-time
#clock-time-midnight
#clock-time-noon
#clock-time-morning
#clock-time-afternoon
#military-time
#military-time-midnight
#military-time-noon
#military-time-morning
#military-time-afternoon
#nato-time
#nato-time-union
#short-date
#short-date-eu
#full-date
#full-date-eu
#set-time
#elapse-8-minutes
#elapse-9-minutes
#elapse-60-minutes
#elapse-720-minutes
#elapse-past-midnight
#elapse-multiple-days
#elapse-4-hours
#elapse-23-hours
#elapse-25-hours
#elapse-3-days
#elapse-11-days
#elapse-12-days
])
(current time 531)
(current date [12 1 1969])
(clean up $) (set time [531 12 1 1969])
(now) (using north american dates)
(test #hours-minutes)
(8 hours 51 minutes)
(test #hours-minutes-zero)
(now) (current time 0)
(0 hours 0 minutes)
(test #hours-minutes-after-midnight)
(now) (current time 1441)
(24 hours 1 minutes)
(test #leading-zero-zero)
(collect words) (leading zero 0) (into $Words)
($Words = [0 0])
(test #leading-zero-one)
(collect words) (leading zero 1) (into $Words)
($Words = [0 1])
(test #leading-zero-nine)
(collect words) (leading zero 9) (into $Words)
($Words = [0 9])
(test #leading-zero-ten)
(collect words) (leading zero 10) (into $Words)
($Words = [10])
(test #clock-time)
(collect words) (clock time) (into $Words)
($Words = [8 : 51 am])
(test #clock-time-midnight)
(now) (current time 0)
(collect words) (clock time) (into $Words)
($Words = [12 : 0 0 am])
(test #clock-time-noon)
(now) (current time 720)
(collect words) (clock time) (into $Words)
($Words = [12 : 0 0 pm])
(test #clock-time-morning)
(now) (current time 390)
(collect words) (clock time) (into $Words)
($Words = [6 : 30 am])
(test #clock-time-afternoon)
(now) (current time 980)
(collect words) (clock time) (into $Words)
($Words = [4 : 20 pm])
(test #military-time)
(collect words) (military time) (into $Words)
($Words = [0 8 : 51])
(test #military-time-midnight)
(now) (current time 0)
(collect words) (military time) (into $Words)
($Words = [0 0 : 0 0])
(test #military-time-noon)
(now) (current time 720)
(collect words) (military time) (into $Words)
($Words = [12 : 0 0])
(test #military-time-morning)
(now) (current time 390)
(collect words) (military time) (into $Words)
($Words = [0 6 : 30])
(test #military-time-afternoon)
(now) (current time 980)
(collect words) (military time) (into $Words)
($Words = [16 : 20])
(test #nato-time)
(collect words) (nato time) (into $Words)
($Words = [12 0 8 51 jan 69])
(test #nato-time-union)
(set time [750 5 3 2273])
(collect words) (nato time) (into $Words)
($Words = [0 5 12 30 mar 73])
(test #short-date)
(collect words) (short date) (into $Words)
($Words = [1 \/ 12 \/ 1969])
(test #short-date-eu)
(now) ~(using north american dates)
(collect words) (short date) (into $Words)
($Words = [12 - 1 - 1969])
(test #full-date)
(collect words) (full date) (into $Words)
($Words = [January 12 , 1969])
(test #full-date-eu)
(now) ~(using north american dates)
(collect words) (full date) (into $Words)
($Words = [12 January , 1969])
(test #set-time)
(set time [430 13 1 1969])
(7 hours 10 minutes)
(current date [13 1 1969])
(test #elapse-8-minutes)
(elapse 8 minutes)
(8 hours 59 minutes)
(test #elapse-9-minutes)
(elapse 9 minutes)
(9 hours 0 minutes)
(test #elapse-60-minutes)
(elapse 60 minutes)
(9 hours 51 minutes)
(test #elapse-720-minutes)
(elapse 720 minutes)
(20 hours 51 minutes)
(test #elapse-past-midnight)
(elapse 1339 minutes)
(7 hours 10 minutes)
(current date [13 1 1969])
(test #elapse-multiple-days)
(elapse 4320 minutes)
(8 hours 51 minutes)
(current date [15 1 1969])
(test #elapse-4-hours)
(elapse 4 hours)
(12 hours 51 minutes)
(test #elapse-23-hours)
(elapse 23 hours)
(7 hours 51 minutes)
(current date [13 1 1969])
(test #elapse-25-hours)
(elapse 25 hours)
(9 hours 51 minutes)
(current date [13 1 1969])
(test #elapse-3-days)
(elapse 3 days)
(8 hours 51 minutes)
(current date [15 1 1969])
(test #elapse-11-days)
(elapse 11 days)
(current date [23 1 1969])
(test #elapse-12-days)
(elapse 12 days)
(current date [24 1 1969])