~ubuntu-branches/ubuntu/hoary/inform/hoary

« back to all changes in this revision

Viewing changes to html/answers1/answer25.html

  • Committer: Bazaar Package Importer
  • Author(s): Mark Baker
  • Date: 2004-03-29 23:52:44 UTC
  • Revision ID: james.westby@ubuntu.com-20040329235244-fox1z1yv7d6vojoo
Tags: upstream-6.30
ImportĀ upstreamĀ versionĀ 6.30

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<HTML><HEAD><TITLE>Answer to Exercise 25</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 25</B><TR><TD><TD>
 
4
<P>
 
5
 
 
6
<PRE>
 
7
[ PrintTime x; print (x/60), ":", (x%60)/10, (x%60)%10; ];
 
8
Object -&#62; alarm_clock "alarm clock"
 
9
  with name "alarm" "clock",
 
10
       number 480,
 
11
       description
 
12
       [;  print "The alarm is ";
 
13
           if (self has general) print "on, "; else print "off, but ";
 
14
           "the clock reads ", (PrintTime) the_time,
 
15
           " and the alarm is set for ", (PrintTime) self.number, ".";
 
16
       ],
 
17
       react_after
 
18
       [;  Inv:  if (self in player)   { new_line; &#60;&#60;Examine self&#62;&#62;; }
 
19
           Look: if (self in location) { new_line; &#60;&#60;Examine self&#62;&#62;; }
 
20
       ],
 
21
       daemon
 
22
       [;  if (the_time &#62;= self.number &#38;&#38; the_time &#60;= self.number+3
 
23
               &#38;&#38; self has general) "^Beep! Beep! The alarm goes off.";
 
24
       ],
 
25
       grammar [; return 'alarm,'; ],
 
26
       orders
 
27
       [;  SwitchOn:  give self general; StartDaemon(self); "~Alarm set.~";
 
28
           SwitchOff: give self ~general; StopDaemon(self); "~Alarm off.~";
 
29
           SetTo:     self.number=noun; &#60;&#60;Examine self&#62;&#62;;
 
30
           default: "~Commands are on, off or a time of day only, pliz.~";
 
31
       ],
 
32
       life
 
33
       [;  Ask, Answer, Tell:
 
34
              "[Try ~clock, something~ to address the clock.]";
 
35
       ],
 
36
  has  talkable;
 
37
</PRE>
 
38
 
 
39
and add a new verb to the grammar:
 
40
<PRE>
 
41
Verb "alarm," * "on"      -&#62; SwitchOn
 
42
              * "off"     -&#62; SwitchOff
 
43
              * TimeOfDay -&#62; SetTo;
 
44
</PRE>
 
45
 
 
46
(using the <TABLE Border><TR><TD><TT>TimeOfDay</TT></TABLE> token from the exercises of <A HREF="section27.html">Section 27</A>).  Note
 
47
that since the word "alarm,'' can't be matched by anything the player types,
 
48
this verb is concealed from ordinary grammar.  The orders we produce here
 
49
are not used in the ordinary way (for instance, the action <TT>SwitchOn</TT> with
 
50
no <TT>noun</TT> or <TT>second</TT> would never ordinarily be produced by the parser) but this
 
51
doesn't matter: it only matters that the grammar and the <TT>orders</TT> property
 
52
agree with each other.
 
53
</TABLE>
 
54
<HR>Back to <A HREF="../section16.html#ex25">the exercise in section 16</A><HR>
 
55
<SMALL><I>Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright &#169; Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.</I></SMALL></BODY></HTML>