A running clock

Shadowalker
I was wondering if there is some way to make a clock that runs, from 12 am to 12 pm. Every second is another minute. I started to make one, using timers and numeric variables, but it was so complicated and confusing, that it just sort of became a huge mess. Anyway, I deleted most of the code, but I have some of it left, and I'm just gonna post it, so someone can hopefully look at it, and tell me what I can do to fix it, or some easier way to make a clock. If you run the file, you will see that I can't make it say 12:00, because I checked off "don't display if = to 0". If I don't check it off, then when it changes to 1:00, it will also say 12:00. So I created a string variable with 12:00, but .......here I go rambling. It'd probably be easier to just take a look. Thanks, if anyone can help...

' "Test Time"
' Created with QDK 3.53 - UNREGISTERED VERSION

define game <Test Time>
asl-version <350>
gametype singleplayer
start <Start Room>
game author <>
game version <1.0>
game copyright <© 2005 >
game info <Created with QDK 3.53 - UNREGISTERED EVALUATION VERSION.>
startscript {
inc <am; 1>
inc <clock 12 1 string; 1>
}
define variable <am>
type numeric
value <0>
display nozero < A.M.>
end define
define variable <pm>
type numeric
value <0>
display nozero < P.M.>
end define
define variable <clock 12 1 string>
type numeric
value <0>
display nozero <Time: 12:00>
end define
define variable <clock 12 1>
type numeric
value <0>
display nozero <Time: 12:0!>
onchange if ( %clock 12 1% = 10 ) then {
timeroff <clock 12 1>
dec <clock 12 1; 10>
inc <clock 12 2; 9>
timeron <clock 12 2>
}
end define
define variable <clock 12 2>
type numeric
value <0>
display nozero <Time: 12:!>
onchange {
if ( %clock 12 2% = 60 ) then {
timeroff <clock 12 2>
dec <clock 12 2; 60>
timeron <clock 1 1 string>
}
}
end define
define variable <clock 1 1 string>
type numeric
value <0>
display nozero <Time: 1:00>
end define
define variable <clock 1 1>
type numeric
value <0>
display nozero <Time: 1:0>
end define
end define

define synonyms
end define

define room <Start Room>
end define

define timer <clock 12 1 string>
interval <0>
action {
timeroff <clock 12 1 string>
timeron <clock 12 1 string 2>
}
enabled
end define

define timer <clock 12 1>
interval <1>
action inc <clock 12 1; 1>
disabled
end define

define timer <clock 12 1 string 2>
interval <0>
action {
dec <clock 12 1 string; 1>
timeron <clock 12 1>
timeroff <clock 12 1 string 2>
}
disabled
end define

define timer <clock 12 2>
interval <0>
action inc <clock 12 2; 1>
disabled
end define

define timer <clock 1 1 string>
interval <0>
action {
timeroff <clock 1 1 string>
timeron <clock 1 1 string 2>
}
disabled
end define

define timer <clock 1 1 string 2>
interval <0>
action {
dec <clock 1 1 string; 1>
timeroff <clock 1 1 string 2>
timeron <clock 1 1>
}
disabled
end define

define timer <clock 1 1>
interval <1>
action inc <clock 1 1; 1>
disabled
end define

define text <intro>

end define

define text <win>

end define

define text <lose>

end define



Sphinx
Just off the top of my head, might be a better way but if you want every second kept track of somewhere.

1 Timer that runs to 1 second. As you want each second to be a min, just have it increment a variable for minutes.

The timer also activates a script to check to see if the variable has reached 60, at which time add 1 to a variable for hours and reset minutes to 0.

The script also checks to see if the hour variable is great than 12. If so then alter it to 1 and alter am - pm or vica versa.

When you look at the clock you just need to display the #hour# variable then the #minutes# #am/pm# variable's and that should do it.

Shadowalker
I think I got most of what you said, but I'm not entirely sure. And if I understood you correctly, it wouldn't work, because you can't increment a string variable, which is what you were suggesting. Anyway, thanks for the idea. I found a way to make the clock work, though it's not as good as I wanted it to be.

Sphinx
Why would you make it a string variable? :) numeric for the numbers would work fine.

The only string variable's you'd need would be AM-PM. These could be swapped around in an IF statement.

007bond
Someone wrote some some clock code once, but that was a long time ago. If you want you can look through the backlog of posts, or just write your own :D

paul_one
That was ITID... HE wrote it for QuestNet.

... You WOULD use a string status variable (IMO)...
Then change that status variable whenever the timer is changed:

snippet 1: (in startscript {} )
flag on <AM>
set numeric <time[1]; 0> ' Seconds
set numeric <time[2]; 0> ' Minutes
set numeric <time[3]; 0> ' Hours

snippet 2:
define variable <time>
type string
value <0:0:0 AM>
display <Time = !>
end define

snippet 3:
timer <time>
interval <1> ' 1 second right?
script {
inc <time[1]>
if (%time[1]% = 60) then {
set <%time[1]%; 0>
inc <%time[2]%>
if (%time[2]% = 60) then {
set <%time[2]%; 0>
inc <%time[3]%>
if (%time[3]% = 12) then {
set <%time[3]%; 0>
flag off <AM>
}
}
}
set <time; %time[1]%:%time[2]%:%time[3]%>
if flag <AM> then set <time; #time# AM> else set <time; #time# PM>
}


Right, I think that's all... I will test it in a little bit, but I just typed it out right now so don't be suprised if it doesn't work straight away...

steve the gaming guy
Ok, here's what I came up with while manipulating CW's code in QDK. It seems to work but I cannot get around the display showing the format as 0:0:0 instead of 00:00:00 once the timer actually starts. It begins as 00:00:00 but when it starts to increment, it changes to 0:0:1

' "Test Time"
' Created with QDK 3.53 - UNREGISTERED VERSION

define game <Test Time>
asl-version <350>
gametype singleplayer
start <room 1>
game author <Eli Schwartz>
game version <1.0>
game copyright <© 2005 Eli Schwartz>
game info <Created with QDK 3.53 - UNREGISTERED EVALUATION VERSION.>
startscript {
flag on <AM>
set numeric <time[1]; 0>
set numeric <time[2]; 0>
set numeric <time[3]; 0>
}
define variable <time>
type string
value <00:00:00 AM>
display <Time = !>
end define

define room <room1>
end define
end define

define synonyms
end define

define room <room 1>
end define

define timer <time>
interval <1>
action {
inc <time[1]>
if ( %time[1]% = 60 ) then {
set numeric <time[1]; 00>
inc <time[2]; 1>
if ( %time[2]% = 60 ) then {
set numeric <time[2]; 00>
inc <time[3]; 1>
if ( %time[3]% = 12 ) then {
set numeric <time[3]; 00>
flag off <AM>
}
}
}
set string <time; %time[3]%:%time[2]%:%time[1]%>
if flag <AM> then set string <time; #time# AM> else set string <time; #time# PM>
}
enabled
end define

define text <intro>

end define

define text <win>

end define

define text <lose>

end define

paul_one
yeah, for 2 significant figures you can use this function:

define function <SF2>
set string <returning; ERROR>
if ($numberparameters$ = 1) then {
set string <temp; $parameter(1)$>
if ($lengthof(#temp#)$ < 2) then set <returning; 0$parameter(1)$> else set <returning; $parameter(1)$>
}
return <#returning#>

end define


That makes sure it's 2 figures..... At least in my brain.... use this when you give the string time a value... Ie:
set string <time; $SF2(#time[1]#)$:etc...>

That way it should work.

Shadowalker
Thanks for all the help guys. I haven't had time to try out the last codes posted, but I'll try them soon. I also modified (actually, I re-wrote it entirely) my code and wrote a new clock one. Originally, I wanted it to say, "Time: 12:00 A.M." in that format, but I couldn't get it to work. It's too long to explain why. You will see what I mean if you try the first code that I posted. Anyway, my new one displays it like this: "A.M.
Hour: 12
Minute*s*: 5"
I guess it's ok. But maybe yours are better. I'll check em out soon.

steve the gaming guy
Computer Whizz wrote:yeah, for 2 significant figures you can use this function:

define function <SF2>
set string <returning; ERROR>
if ($numberparameters$ = 1) then {
set string <temp; $parameter(1)$>
if ($lengthof(#temp#)$ < 2) then set <returning; 0$parameter(1)$> else set <returning; $parameter(1)$>
}
return <#returning#>

end define


That makes sure it's 2 figures..... At least in my brain.... use this when you give the string time a value... Ie:
set string <time; $SF2(#time[1]#)$:etc...>

That way it should work.


CW, why are we setting the string returning as ERROR? I got the code all entered and now it shows the time as ERROR:ERROR:ERROR

paul_one
You get an error because you're not giving the function a parameter... That's the only way you get "ERROR" back.

I'm just going to put all this down and try it out... Hang on.

::EDIT::
Haven't tested it yet - but just spotted a minor error.
it should be $SF2(%time[1]%)$ ..... whereas I put #time[1]#....
I'm just about to try it out now...

::EDIT2::
Right, I say you change these lines:
%time[1]% = 60     :CHANGE TO:     %time[1]% > 59
%time[2]% = 60 :CHANGE TO: %time[2]% > 59
%time[3]% = 12 :CHANGE TO: %time[3]% > 11

But it works.... Output is 00:00:00 AM
then 00:00:01 AM

::EDIT3::
BIG error!
Once it reaches PM it will remain PM until the end of time....
Erm, anyway, replace this line:
flag off <AM>
with:
if flag <AM> then flag off <AM> else flag on <AM>

Simple enough eh!?
Right, that should do.

Shadowalker
Ok, I'm a little confused...there's been so many re-posts and such that I'm not sure which code to try out.....?

Shadowalker
Sorry about this double post...I just wanted to post the code I made for the clock. As I said in the other post, I'm not sure which code to try, as it's been edited a bunch of times, but I gather it looks something like "00:00:00" with an A.M. or P.M. See, I wanted it to look more like "12:00 A.M." etc.. But since that didn't work, I made something similar enough. So here's the code...can someone tell me if it looks ok? Also, I added a command that if you type in "t" it will let you change the time. Thanks a ton
' "Test Time"
' Created with QDK 3.53 - UNREGISTERED VERSION

define game <Test Time>
asl-version <350>
gametype singleplayer
start <Start>
game author <>
game info <Created with QDK 3.53 - UNREGISTERED EVALUATION VERSION.>
command <t> {
msg <What would you like the hour to be? (ENTER A NUMBER FROM 1-12)|n|n>
enter <hour>
if ( #hour# = 1 ) or ( #hour# = 2 ) or ( #hour# = 3 ) or ( #hour# = 4 ) or ( #hour# = 5 ) or ( #hour# = 6 ) or ( #hour# = 7 ) or ( #hour# = 8 ) or ( #hour# = 9 ) or ( #hour# = 10 ) or ( #hour# = 11 ) or ( #hour# = 12 ) then {
set <hours; #hour#>
msg <Ok, the hour is now: %hours%.|n>
pause <1500>
msg <Would would you like the minute(s) to be? (PLEASE ENTER A NUMBER FROM 1-59)|n>
enter <minute>
if ( #minute# >= 1 ) and ( #minute# <= 59 ) then {
set <minutes; #minute#>
msg <The minute(s) is/are now: %minutes%.|n>
pause <1500>
msg <Would you like it to be A.M., or P.M.? (PLEASE ENTER "1" FOR A.M., OR "2" FOR P.M.)|n>
enter <a or p>
if ( #a or p# = 1 ) or ( #a or p# = 2 ) then {
if ( #a or p# = 1 ) then {
set <A.M.; 1>
set <P.M.; 0>
msg <It is now: A.M.|n>
pause <1500>
msg <Your new settings: |nHour: %hours%.|nMinute(s): %minutes%.|nM: A.M.|n>
}
if ( #a or p# = 2 ) then {
set <P.M.; 1>
set <A.M.; 0>
msg <It is now: P.M.|n>
pause <1500>
msg <Your new settings: |nHour: %hours%.|nMinute(s): %minutes%.|nM: P.M.|n>
}
}
else msg <I'm sorry, but you chose an invalid selection. Please try again later.|n>
}
else msg <I'm sorry, but that number is not valid. Please try again later.|n>
}
else msg <I'm sorry, but that number is not valid. Please try again later.|n>
}
define variable <A.M.>
type numeric
value <1>
display nozero < A.M.>
end define
define variable <P.M.>
type numeric
value <0>
display nozero < P.M.>
end define
define variable <hours>
type numeric
value <12>
display <Hour: !>
end define
define variable <minutes>
type numeric
value <00>
display <Minute*s*: !>
onchange {
if ( %minutes% = 60 ) then {
dec <minutes; 60>
do <Increment Hour>
}
if ( %minutes% = 59 ) then do <A.M. and P.M.>
if ( %minutes% = 29 ) and ( %hours% = 8 ) and ( %A.M.% = 1 ) then give <Kol Tuv Open>
if ( %minutes% = 29 ) and ( %hours% = 9 ) and ( %P.M.% = 1 ) then lose <Kol Tuv Open>
}
end define
end define

define synonyms
end define

define room <Start>
look <A store is nearby. >
description {
msg <You are in the |crStarting|cb room.|n>
msg <#quest.lookdesc#|n>
}
end define

define procedure <Increment Hour>
if ( %hours% = 12 ) then dec <hours; 11> else inc <hours; 1>

end define

define procedure <A.M. and P.M.>
if ( %hours% = 11 ) and ( %A.M.% = 1 ) then {
dec <A.M.; 1>
inc <P.M.; 1>
}
else {
if ( %hours% = 11 ) and ( %P.M.% = 1 ) then {
dec <P.M.; 1>
inc <A.M.; 1>
}
}
end define

define timer <minutes>
interval <1>
action set <minutes; %minutes%+1>
enabled
end define

define text <intro>

end define

define text <win>

end define

define text <lose>

end define



steve the gaming guy
I still come up with ERROR:ERROR:ERROR. I will fiddle with the code some more. Ebayfan, I will try your code just to see how it works. It's interesting that you can choose the time and change the time but I don't know how I would use it in a game.
On a side note, why would Santa empty a boy's sac? Ok, I'm making a joke about a joke. But that was baaaad.

paul_one
Steve - here's the code in full (had to re-make it as the one I had - I deleted and emptied the bin)...

'' "Test Time"
' Created with QDK 3.53 - UNREGISTERED VERSION

define game <Test Time>
asl-version <350>
gametype singleplayer
start <room 1>
game author <Eli Schwartz>
game version <1.0>
game copyright <© 2005 Eli Schwartz>
game info <Created with QDK 3.53 - UNREGISTERED EVALUATION VERSION.>
startscript {
flag on <AM>
set numeric <time[1]; 0>
set numeric <time[2]; 0>
set numeric <time[3]; 0>
}
define variable <time>
type string
value <00:00:00 AM>
display <Time = !>
end define

command <set #hour#:#minute# #AorP#> {
if (#hour# >= 0) and (#hour# < 12) then set numeric <time[3]; #hour#> else msg <Hour isn't between 0 and 12!>
if (#minutes# >= 0) and (#minutes# < 60 ) then set numeric <time[2]; #minute#> else msg <Minute's aren't between 0 and 60!>
if ($lcase(#AorP#)$ = am) then flag on <AM> else {if ($lcase(#AorP#)$ = pm) then flag off <AM> else msg <#AorP# is not AM or PM!>}
msg <The time has been set to: #time#...>
}

end define

define synonyms
end define

define room <room 1>
end define

define timer <time>
interval <1>
action {
inc <time[1]>
if ( %time[1]% > 59 ) then {
set numeric <time[1]; 00>
inc <time[2]>
if ( %time[2]% > 59 ) then {
set numeric <time[2]; 00>
inc <time[3]>
if ( %time[3]% > 11 ) then {
set numeric <time[3]; 00>
if flag <AM> then flag off <AM> else flag on <AM>
}
}
}
set string <time; $SF2(%time[3]%)$:$SF2(%time[2]%)$:$SF2(%time[1]%)$>
if flag <AM> then set string <time; #time# AM> else set string <time; #time# PM>
}
enabled
end define

define function <SF2>
set string <returning; ERROR>
if ($numberparameters$ = 1) then {
set string <temp; $parameter(1)$>
if ($lengthof(#temp#)$ < 2) then set <returning; 0$parameter(1)$> else set <returning; $parameter(1)$>
}
return <#returning#>

end define

define text <intro>

end define

define text <win>

end define

define text <lose>

end define

What are you doing differently Steve?

Ebayfan - I've put in a command to st the time here too, it's alot simpler!

steve the gaming guy
Oh I see yours is a lot fancier than what I'm using. I don't have time to try to understand yours at the moment but I will look at yours in depth sometime today.
In the meantime, this is the version I had. It's similar to the first one but I made the changes as indicated in your next to last post, CW and this is how it looks now:

' "Test Time"
' Created with QDK 3.53 - UNREGISTERED VERSION

define game <Test Time>
asl-version <350>
gametype singleplayer
start <room 1>
game author <Eli Schwartz>
game version <1.0>
game copyright <© 2005 Eli Schwartz>
game info <Created with QDK 3.53 - UNREGISTERED EVALUATION VERSION.>
startscript {
flag on <AM>
set numeric <time[1]; 0>
set numeric <time[2]; 0>
set numeric <time[3]; 0>
}
define variable <time>
type string
value <00:00:00 AM>
display <Time = !>
end define
define room <room1>
end define
end define

define synonyms
end define

define room <room 1>
end define

define function <SF2>
set string <returning; ERROR>
if ( $numberparameters$ = 1 ) then {
set string <temp; $parameter(1)$>
if ( $lengthof(#temp#)$ < 2 ) then set <returning; 0$parameter(1)$> else set <returning; $parameter(1)$>
}
return <#returning#>

end define

define timer <time>
interval <1>
action {
inc <time[1]>
if ( %time[1]% > 59 ) then {
set numeric <time[1]; 00>
inc <time[2]; 1>
if ( %time[2]% > 59 ) then {
set numeric <time[2]; 00>
inc <time[3]; 1>
if ( %time[3]% > 11 ) then {
set numeric <time[3]; 00>
if flag <AM> then flag off <AM> else flag on <AM>
}
}
}
set string <time; $SF2(#time[3]#)$:$SF2(#time[2]#)$:$SF2(#time[1]#)$>
if flag <AM> then set string <time; #time# AM> else set string <time; #time# PM>
}
enabled
end define

define text <intro>

end define

define text <win>

end define

define text <lose>

end define



I will try yours out.

steve the gaming guy
That's pretty cool. Again, I don't know how I would use it in a game. But I tested CW's code and it does what it's supposed to do. I'm not going to mess with it anymore unless in the future, I need a clock and I'll come back to it. But I wanted to mention there was a little bugginess where you change the time. If you say set 11:11:11 AM (or whatever time), the clock does change to the time you said but the statement that gets put out is something like: You've changed the time to 00:00:01 AM or something similar.
No biggy but it was something I noted.
Great work. Good question to begin with, Ebayfan.

paul_one
You can use it in a game for a load of things.

How set 11:11:11 AM would work I don't know - I only allowed "set #hour#:#min# #AoP#" ....
ANYWAY, yeah - it just print's the time... You can always set a variable to time3:time2:time1 and then add AM or PM..... Like I did in the timer....

::EDIT::
A 'clock' can be quite useful, if you want to change text/objects/whatever according to certain times... You can also see how long people took to play the game. It's also useful in MUD's.

Shadowalker
Hi guys. Thanks for all the help. I tried to use the codes posted, but after I paste it and then run it, it gets an error message. It says "Missing end define." Any idea why? I looked at the end of the code and it has an end define, so I'm not sure what the trouble is....I must be doing something wrong...

On a side note, why would Santa empty a boy's sac? Ok, I'm making a joke about a joke. But that was baaaad.

It means that Santa empties out the little boy's sack...meaning that he has a sack of toys for the boy, and he empties it out...i like the joke lol :D

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums