1
<HTML><HEAD><TITLE>Section 32: Boxes, menus and drawings</TITLE></HEAD>
2
<BODY BGCOLOR="#FFFFFF">
4
<TR><TD Valign="top"><A HREF="contents.html">Contents</A><BR><A HREF="section31.html">Back</A><BR><A HREF="section33.html">Forward</A><TD bgcolor="#F5DEB3"><BLOCKQUOTE><H3>32. Boxes, menus and drawings</H3></BLOCKQUOTE><TR><TD><TD>
8
Yes, all right, I won't do the menu... I don't think you realise
9
how long it takes to do the menu, but no, it doesn't matter, I'll
10
hang the picture now. If the menus are late for lunch it doesn't
11
matter, the guests can all come and look at the picture till they
13
<P>...John Cleese and Connie Booth, <I>Fawlty Towers</I></BLOCKQUOTE>
17
One harmless effect, though not very special, is to ask the player
18
a yes/no question. To do this, print up the question and then
19
call the library routine <TT>YesOrNo</TT>, which returns true/false
23
The status line is perhaps the most distinctive feature of Infocom games in
24
play. This is the (usually highlighted) bar across the top of the screen.
25
Usually, the game automatically prints the current game location, and either
26
the time or the score and number of turns taken. It has the score/turns
27
format unless the directive
32
has been written in the program, in which case the game's 24-hour clock is
36
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL> If you want to change this, just <TT>Replace</TT> the parser's
37
private <TT>DrawStatusLine</TT> routine. This requires a little assembly
38
language: see the next section for numerous examples.
43
About character graphic drawings: on some machines, text will by default
44
be displayed in a proportional font (i.e., one in which the width of a letter
45
depends on what it is, so that for example an 'i' will be narrower than an
46
'm'). If you want to display a diagram made up of letters, such as a map,
47
the spacing may then be wrong. The statement <TT>font off</TT> ensures that any
48
fancy font is switched off and that a fixed-pitch one is being used: after
49
this, <TT>font on</TT> restores the usual state.
52
<P><TR><TD Valign="top"><IMG SRC="icons/warning.gif" ALT="!!"><TD><B>WARNING:</B><BR> Don't turn the <TT>font</TT> on and off in the middle of a line; this
53
doesn't look right on some machines.
56
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL> When trying to produce a character-graphics drawing, you sometimes
57
want to produce the <TT>\</TT> character, one of the four "escape characters''
58
which can't normally be included in text. A double <TT>@</TT> sign followed by
59
a number includes the character with that ASCII code; thus:
61
<TT>@@64</TT> produces the literal character <TT>@</TT><BR>
62
<TT>@@92</TT> produces <TT>\</TT><SAMP> </SAMP> <TT>@@94</TT> produces <TT>^</TT>
63
<SAMP> </SAMP> <TT>@@126</TT> produces <TT>~</TT><BR>
70
<P><TR><TD Valign="top"><IMG SRC="icons/ddbend.gif" ALT="/\/\"><TD bgcolor="#EEEEEE"><SMALL> Some interpreters are capable of much better character graphics
71
(those equipped to run the Infocom game 'Beyond Zork', for instance).
72
There is a way to find out if this feature is provided and to make
73
use of it: see the <I> Z-Machine Standards Document</I>.
77
<P><TR><TD Valign="top"><IMG SRC="icons/ddbend.gif" ALT="/\/\"><TD bgcolor="#EEEEEE"><SMALL> A single <TT>@</TT> sign is also an escape character. It must be
78
followed by a 2-digit decimal number between 0 and 31 (for instance,
79
<TT>@05</TT>). What this prints is the <I>n</I>-th 'variable string'. This feature
80
is not as useful as it looks, since the only legal values for such
81
a variable string are strings declared in advance by a <TT>LowString</TT>
82
directive. The <TT>String</TT> statement then sets the <I>n</I>-th variable
83
string. For details and an example, see the answer to the east-west
84
reversal exercise in <A HREF="section10.html">Section 10</A>.
89
A distinctive feature of later Infocom games was their use of epigrams.
90
The assembly language required to produce this effect is easy but a
91
nuisance, so there is an Inform statement to do it, <TT>box</TT>. For example,
93
box "I might repeat to myself, slowly and soothingly,"
94
"a list of quotations beautiful from minds profound;"
95
"if I can remember any of the damn things."
100
Note that a list of one or more lines is given (without intervening commas)
101
and that a blank line is given by a null string. Remember that the text
102
cannot be too wide or it will look awful on a small screen. Inform
103
will automatically insert the boxed text into the game transcript,
104
if one is being made.
105
The author takes the view that this device is amusing for irrelevant
106
quotations but irritating when it conveys vital information (such as
107
"Beware of the Dog"). Also, some people might be running
108
your game on a laptop with a vertically challenged screen, so it is
109
polite to provide a "quotes off'' verb.
112
A snag with printing boxes is that if you do it in the middle of a turn
113
then it will probably scroll half-off the screen by the time the game
114
finishes printing for the turn. The right time to do so is just after
115
the prompt (usually <TT>></TT>) is printed, when the screen will definitely
116
scroll no more. You could use the <TT>Prompt:</TT> slot in <TT>LibraryMessages</TT>
117
to achieve this, but a more convenient way is to put your box-printing
118
into the entry point <TT>AfterPrompt</TT> (called at this time each
122
<P><TR><TD Valign="top"><IMG SRC="icons/exercise.gif" ALT="??"><TD bgcolor="#FBB9AC"><A NAME="ex88"><B>EXERCISE 88:</B><BR>(link to <A HREF="answers2/answer88.html">the answer</A>)<TR><TD><TD> Implement a routine <TT>Quote(n)</TT> which will arrange for the
123
<I>n</I>-th quotation (where
125
) to be displayed at the end
126
of this turn, provided it hasn't been quoted
132
Sometimes one would like to provide a menu of text options (for instance,
133
when producing instructions which have several topics, or when giving
134
clues). This can be done with the <TT>DoMenu</TT> routine, which imitates
135
the traditional "Invisiclues'' style. By setting <TT>pretty_flag=0</TT> you
136
can make a simple text version instead; a good idea for machines
137
with very small screens.
138
Here is a typical call to <TT>DoMenu</TT>:
140
DoMenu("There is information provided on the following:^
141
^ Instructions for playing
142
^ The history of this game
147
Note the layout, and especially the carriage returns. The second and
148
third arguments are themselves routines. (Actually the first argument
149
can also be a routine to print a string instead of the string itself,
150
which might be useful for adaptive hints.) The <TT>HelpMenu</TT> routine
151
is supposed to look at the variable <TT>menu_item</TT>. In the case when this
152
is zero, it should return the number of entries in the menu (3 in the
153
example). In any case it should set <TT>item_name</TT> to the title for the
154
page of information for that item; and <TT>item_width</TT> to half its length
155
in characters (this is used to centre titles on the screen).
156
In the case of item 0, the title should be that for the whole
160
The second routine, <TT>HelpInfo</TT> above, should simply look at <TT>menu_item</TT>
161
(1 to 3 above) and print the text for that selection. After this returns,
162
normally the game prints "Press [Space] to return to menu'' but if
163
the value 2 is returned it doesn't wait, and if the value 3 is returned
164
it automatically quits the menu as if Q had been pressed. This is useful
165
for juggling submenus about.
168
Menu items can safely launch whole new menus, and it is easy to make
169
a tree of these (which will be needed when it comes to providing hints
170
across any size of game).
173
<P><TR><TD Valign="top"><IMG SRC="icons/exercise.gif" ALT="??"><TD bgcolor="#FBB9AC"><A NAME="ex89"><B>EXERCISE 89:</B><BR>(link to <A HREF="answers2/answer89.html">the answer</A>)<TR><TD><TD> Code an "Invisiclues''-style sequence of hints for a puzzle,
174
revealed one at a time, as a menu item.
178
Finally, you can change the text style. The statement for this is
179
<TT>style</TT> and its effects are loosely modelled on the VT100 (design of
180
terminal). The style can be <TT>style roman</TT>, <TT>style bold</TT>, <TT>style reverse</TT> or
181
<TT>style underline</TT>. Again, poor terminals may not be able to display these,
182
so you shouldn't hide crucial information in them.
185
<P><TR><TD Valign="top"><IMG SRC="icons/refs.gif" ALT="*"><TD bgcolor="#EEEEEE"><B>REFERENCES:</B><BR><SMALL> 'Advent' contains a menu much like that above.
187
The "Infoclues'' utility program translates UHS format hints
188
(a standard, easy to read and write layout) into an Inform file of calls to
189
<TT>DoMenu</TT> which can simply be included into a game; this saves a good deal of
192
<HR><A HREF="contents.html">Contents</A> / <A HREF="section31.html">Back</A> / <A HREF="section33.html">Forward</A> <BR>
193
<A HREF="chapter1.html">Chapter I</A> / <A HREF="chapter2.html">Chapter II</A> / <A HREF="chapter3.html">Chapter III</A> / <A HREF="chapter4.html">Chapter IV</A> / <A HREF="chapter5.html">Chapter V</A> / <A HREF="chapter6.html">Chapter VI</A> / <A HREF="chapterA.html">Appendix</A><HR><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>