1
<HTML><HEAD><TITLE>Answer to Exercise 39</TITLE></HEAD>
2
<BODY BGCOLOR="#FFFFFF">
3
<TABLE><TR><TD Valign="top"><IMG SRC="../icons/exercise.gif" ALT="??"><TD bgcolor="#FAA89B"><B>ANSWER TO EXERCISE 39</B><TR><TD><TD>
7
A minimal solution is as follows:
9
Constant SUNRISE 360; ! i.e., 6 am
10
Constant SUNSET 1140; ! i.e., 7 pm
11
Attribute outdoors; ! Give this to external locations
12
Attribute lit; ! And this to artificially lit ones
15
if (the_time >= SUNRISE && the_time < SUNSET) f=1;
16
if (day_state == f) rfalse;
18
{ if (obj has lit) give obj light;
19
if (obj has outdoors && obj hasnt lit)
20
{ if (f==0) give obj ~light; else give obj light;
23
if (day_state==2) { day_state = f; return; }
24
day_state = f; if (location hasnt outdoors) return;
25
if (f==1) "^The sun rises, illuminating the landscape!";
26
"^As the sun sets, the landscape is plunged into darkness.";
30
In the <TT>Initialise</TT> routine, set the time (using <TT>SetTime</TT>)
31
and then call <TT>TimePasses</TT> to set all the <TT>light</TT> attributes
32
accordingly. Note that with this system, there's no need to
33
set <TT>light</TT> at all: that's automatic.
35
<HR>Back to <A HREF="../section18.html#ex39">the exercise in section 18</A><HR>
36
<SMALL><I>Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright © Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.</I></SMALL></BODY></HTML>