Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Inform] Making clocks...?

1 view
Skip to first unread message

The Editor

unread,
Oct 25, 1998, 2:00:00 AM10/25/98
to
OK, maybe I'd better get this question out of my way while I'm still in
the design stage, *before* I get my heart set on something that turns
out to be impossible... ;) Bear with me, I'm a beginner at this --
playing veteran, yes, but until now I've successfully resisted the siren
lure of the programming end...

The game I'm thinking of making involves a house of the modern period,
which in the way of things probably means that most of the electronic
gadgets present (microwave, VCR, etc) will have clocks (and no, having
them all flashing "12:00" would be the coward's way out ;) ). The game
will probably be given a set completion-by time. Now, the player is
going to want to check the time he/she has left periodically, right...?

Question #1 (which even I recognize as being pretty basic): how do I
stick relevant clocks on things? (displaying the game-time, I mean)
Watches would also be useful.

Question #2, which gets into the more fiendish end of my reason for
asking this: how do I set some of the clocks *WRONG*? [EG] Because if
this is anything like any of the houses I'm familiar with, no two clocks
in it will ever be displaying the same time (I can see three from where
I'm sitting now, for example: 12:23, 12:24, and 12:26). I vaguely have
in mind to complicate a computer-related puzzle by setting its
clock-display *wildly* wrong.

I know I've seen clocks implemented... somewhere... so I guess the real
meat of this question is whether Q2 is something I should be designing
for at this stage, or whether I should modify my idea *before* I run
into heartache... Thanks!

S Lynn
mailto:JeremiasD
Famous Last Words: "I thought Inform would be a more entertaining
introduction to programming than C..."

Joe Mason

unread,
Oct 25, 1998, 2:00:00 AM10/25/98
to
The Editor <city...@mcs.net> wrote (not insribed, ok? wrote):

>OK, maybe I'd better get this question out of my way while I'm still in
>the design stage, *before* I get my heart set on something that turns
>out to be impossible... ;) Bear with me, I'm a beginner at this --
>playing veteran, yes, but until now I've successfully resisted the siren
>lure of the programming end...

Clocks should be no problem at all.

>Question #1 (which even I recognize as being pretty basic): how do I
>stick relevant clocks on things? (displaying the game-time, I mean)
>Watches would also be useful.

See Question 2, since the answer to that will answer this one as well.

>Question #2, which gets into the more fiendish end of my reason for
>asking this: how do I set some of the clocks *WRONG*? [EG] Because if
>this is anything like any of the houses I'm familiar with, no two clocks
>in it will ever be displaying the same time (I can see three from where
>I'm sitting now, for example: 12:23, 12:24, and 12:26). I vaguely have
>in mind to complicate a computer-related puzzle by setting its
>clock-display *wildly* wrong.

Simple. Make a routine that takes a number (of seconds) and spits it back as
hours/minutes/seconds. Here's one from a code snippet of mine on GMD:

[ Time the_time h m s;
if (the_time < 0) the_time = 0;
h = the_time / 3600;
m = the_time % 3600 / 60;
s = the_time % 3600 % 60;
print h, ":";
if (m < 10) print "0";
print m, ":";
if (s < 10) print "0";
print s;
rtrue;
];

Now you can use this in print statements just like Inform's built-in print
formatters: (The) noun, (noun) noun, (number) num, etc:

print "The clock on the microwave reads ", (time) microwave.number, ".^";

Notice I've used microwave.number to store the time. Just store the time in
seconds in a property ("number" is good, unless you're already using it for
something else) and then use your (time) routine to print it out. The "true"
time can be stored in a global variable, and printed with the same routine,
thus answering Question 1 as well.

The one thing you have to worry about is wrapping the time around to 0 again
at midnight. There are (60*60*24) seconds in a day, so if you've got a number
storing a time, you can adjust it with

time % (60 * 60 * 24)

So that if the number is higher than 24 hours, it'll wrap it around.

The timer code I posted is in the brief sample code on GMD included with

.../inform6/library/contributions/inform-realtime-hack.tar.gz

It contains a pair of timers which count down (in real time), storing different
times remaining in each. You can use the same principles, just adjusting your
clocks every turn instead of every second.

Joe
--
I think OO is great... It's no coincidence that "woohoo" contains "oo" twice.
-- GLYPH

The Editor

unread,
Oct 25, 1998, 2:00:00 AM10/25/98
to
Joe Mason wrote:


> Simple. Make a routine that takes a number (of seconds) and spits it back as

> hours/minutes/seconds. Here's one from a code snippet of mine on GMD: {{SNIP}}


{scribble scribble STUDY scribble} The really scary part is, this makes
sense and I haven't even started the coding yet... ;) I should probably
be thinking about a nice long vacation in the Rubber Room rather than
starting a project like this. But then, I've always thought that sanity
is rather overrated anyway...


> The one thing you have to worry about is wrapping the time around to 0 again
> at midnight.


...Fortunately, the plan calls for the gametime running out at 6 pm. ;)


> The timer code I posted is in the brief sample code on GMD included with
>
> .../inform6/library/contributions/inform-realtime-hack.tar.gz
>
> It contains a pair of timers which count down (in real time), storing different
> times remaining in each. You can use the same principles, just adjusting your
> clocks every turn instead of every second.


Darn, and here I was hoping to get through this without having to
remember where I stored my unTARring utilities... ;) Thanks for the
speedy answer!


S Lynn
mailto:Jere...@aol.com
Famous Last Words: KILL DWARF WITH ZUCCHINI

Andrew Plotkin

unread,
Oct 25, 1998, 2:00:00 AM10/25/98
to
Joe Mason (jcm...@uwaterloo.ca) wrote:

> Simple. Make a routine that takes a number (of seconds) and spits it back as
> hours/minutes/seconds. Here's one from a code snippet of mine on GMD:

> [ Time the_time h m s;


> if (the_time < 0) the_time = 0;
> h = the_time / 3600;
> m = the_time % 3600 / 60;
> s = the_time % 3600 % 60;
> print h, ":";
> if (m < 10) print "0";
> print m, ":";
> if (s < 10) print "0";
> print s;
> rtrue;
> ];

> Now you can use this in print statements just like Inform's built-in print
> formatters: (The) noun, (noun) noun, (number) num, etc:

> print "The clock on the microwave reads ", (time) microwave.number, ".^";

> Notice I've used microwave.number to store the time. Just store the time in
> seconds in a property ("number" is good, unless you're already using it for
> something else) and then use your (time) routine to print it out. The "true"
> time can be stored in a global variable, and printed with the same routine,
> thus answering Question 1 as well.

> The one thing you have to worry about is wrapping the time around to 0 again


> at midnight. There are (60*60*24) seconds in a day, so if you've got a number
> storing a time, you can adjust it with

> time % (60 * 60 * 24)

> So that if the number is higher than 24 hours, it'll wrap it around.

There's only one leetle problem with this: 60*60*24 is 86400, and the
largest integer the Z-machine can handle is 32767. (Or 65535 if you
interpret them as unsigned -- but you can't do that, because division,
multiplication, and modulo are always signed in the Z-machine.)

So you're going to get very surprising results with the above code.

I'd store times as a *pair* of numbers, probably hours (0 to 24) and
seconds (0 to 3600). It's safe to jigger the seconds value into
minutes-and-seconds by /60 and %60.

--Z

--

"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
borogoves..."

Lucian Paul Smith

unread,
Oct 26, 1998, 3:00:00 AM10/26/98
to
Joe Mason (jcm...@uwaterloo.ca) wrote:

: Simple. Make a routine that takes a number (of seconds) and spits it back as
: hours/minutes/seconds. Here's one from a code snippet of mine on GMD:

Also note: The code Joe posted was written for a real-time game, and you
didn't say if that was actually what you wanted in your game. If you want
every move in the game to take (say) a minute (as in Deadline), use the
same logic, but use basic units of one turn==one minute instead.

Here, I'm intrigued. Here's an object you shouldn't put in any room, but
which you can use to figure out the time, all completely untested:

Object clock
with raw_time 0, !Set this to whatever you want the time to be at the
!beginning of the game.
hour [x y;
if (x==0) x=raw_time;
y=x/60;
if (y>12)
{
return self.hour(x-(12*60));
}
return y;
],
minute [x;
if (x==0) x=raw_time;
return (x - ((x/60)*60)); !This assumes stuff about the way
!Infom does arithmetic--anyone know if
!I'm right?
],
display [x;
if (x==0) x=raw_time;
print self.hour(x), ":", self.minute(x);
],
daemon [; self.raw_time++;];

------------
Once you start up the daemon in Initialize, this clock will keep track of
turn-based time throughout the game. It wouldn't be too big a deal to
change the daemon to update the time in real-time mode, either. To use
this to get the real time, just call clock.display(). To get a clock that
was five minutes fast, call clock.display(clock.real_time + 5). To get AM
and PM to work, you'd need to change clock.hour to return values from 1 to
24, and change the 'display' routine. It might be a good idea for
raw_time to reset itself every 24 hours, too, in case the player is
particularly slow ;-)

Good Luck!

-Lucian


Jonadab the Unsightly One

unread,
Oct 26, 1998, 3:00:00 AM10/26/98
to

: Question #2, which gets into the more fiendish end of my reason

for
: asking this: how do I set some of the clocks *WRONG*? [EG] Because
if
: this is anything like any of the houses I'm familiar with, no two
clocks
: in it will ever be displaying the same time (I can see three from
where
: I'm sitting now, for example: 12:23, 12:24, and 12:26). I vaguely
have
: in mind to complicate a computer-related puzzle by setting its
: clock-display *wildly* wrong.

This can be done. I recommend you have a clock class, and have
every clock inherit from it.

Now, every clock can have its own "off-by" value, which the
clock class checks (and adjusts appropriately) before printing
the time.

--
[Insert hilarious quote here.]

-- jonadab


Schep

unread,
Oct 26, 1998, 3:00:00 AM10/26/98
to
Lucian Paul Smith wrote:
> minute [x;
> if (x==0) x=raw_time;
> return (x - ((x/60)*60)); !This assumes stuff about the way
> !Infom does arithmetic--anyone know if
> !I'm right?
> ],
That should work, yes. But use the modulo operator % (remainder of
integer division, valid for C++ and Inform, many other languages have
something else similar).
That is, (x - ((x/60)*60)) is the same as (x % 60)

--
Schep -----------------------------------------------------
Reply by email should be schepler at pilot dot msu dot edu.
The other automatic one is an anti-spam device.
Nothing against the meat. (yes, spam contains meat)

0 new messages