home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / games / inform / compiler / manuals / Designers next >
Encoding:
Text File  |  1994-10-02  |  291.9 KB  |  7,462 lines

  1. %  TeX source for the Inform Designer's Manual
  2. %  ===========================================
  3.  
  4. %  TeX is a fairly readable mark-up language, but if you
  5. %  can't run it, try the PostScript file or in the last
  6. %  resort the approximate plain-text facsimile.
  7. %  Note that up-arrow signifies "make index entry".
  8.  
  9. \newif\iffiles\filesfalse
  10. %
  11. %  Manual macros
  12. %
  13. %  Page layout
  14. %
  15. \newif\ifshutup\shutupfalse
  16. \magnification=\magstep 1
  17. \hoffset=0.15 true in
  18. \voffset=2\baselineskip
  19. %
  20. %  General hacks
  21. %
  22. \def\PAR{\par}
  23. %
  24. %  Font loading
  25. %
  26. \font\medfont=cmr10 scaled \magstep2
  27. \font\bigfont=cmr10 scaled \magstep3
  28. %\def\sectfont{\bf}
  29. \font\sectfont=cmbx12
  30. \def\small{\sevenrm}
  31. \font\rhrm=cmr8
  32. \font\rhit=cmsl8
  33. %
  34. %  Titles
  35. %
  36. \newcount\subsectno    %  Subsection number
  37. \def\rhead{}           %  The running head will go here
  38. %
  39. \def\newsection#1#2{%     To begin a section...
  40. %\global\titletrue%        Declare this as a title page
  41. \xdef\rhead{{\rhrm #1}\quad #2}%       Initialise running head and ssn
  42. \subsectno=0%
  43. \iffiles
  44. \write\conts{\string\sli\string{#1\string}\string{#2\string}\string{\the\pageno\string}}%
  45. \fi
  46. }
  47. %
  48. \def\section#1#2{\vskip 1 true in\goodbreak\newsection{#1}{#2}
  49. \noindent{\sectfont #1\quad #2}\bigskip\noindent}
  50. %
  51. %  Headers and footers
  52. %
  53. \newif\iftitle
  54. \headline={\iftitle\hfil\global\titlefalse%
  55.            \else{\hfil{\rhit \rhead}}%
  56.            \fi}
  57. \footline={\ifnum\pageno<0\hfil{\tenbf\romannumeral -\pageno}%
  58. \else\hfil{\tenbf \number\pageno}\fi}
  59. %\footline={\ifnum\pageno=1\hfil\else\hfil{\tenbf \number\pageno}\fi}
  60. %
  61. %  (Old date-stamping version:)
  62. % \footline={\hfil{\rm \number\pageno}\hfil{\rm \number\day/\number\month}}
  63. %
  64. % If this works I'll be impressed
  65. %
  66.  
  67. \font\ninerm=cmr9
  68. \font\ninei=cmmi9
  69. \font\ninesy=cmsy9
  70. \font\ninebf=cmbx9
  71. \font\eightbf=cmbx8
  72. \font\ninett=cmtt9
  73. \font\nineit=cmti9
  74. \font\ninesl=cmsl9
  75. \def\ninepoint{\def\rm{\fam0\ninerm}%
  76.   \textfont0=\ninerm
  77.   \textfont1=\ninei
  78.   \textfont2=\ninesy
  79.   \textfont3=\tenex
  80.   \textfont\itfam=\nineit \def\it{\fam\itfam\nineit}%
  81.   \textfont\slfam=\ninesl \def\sl{\fam\slfam\ninesl}%
  82.   \textfont\ttfam=\ninett \def\tt{\fam\ttfam\ninett}%
  83.   \textfont\bffam=\ninebf
  84.   \normalbaselineskip=11pt
  85.   \setbox\strutbox=\hbox{\vrule height8pt depth3pt width0pt}%
  86.   \normalbaselines\rm}
  87.  
  88. \def\tenpoint{\def\rm{\fam0\tenrm}%
  89.   \textfont0=\tenrm
  90.   \textfont1=\teni
  91.   \textfont2=\tensy
  92.   \textfont3=\tenex
  93.   \textfont\itfam=\tenit \def\it{\fam\itfam\tenit}%
  94.   \textfont\slfam=\tensl \def\sl{\fam\slfam\tensl}%
  95.   \textfont\ttfam=\tentt \def\tt{\fam\ttfam\tentt}%
  96.   \textfont\bffam=\tenbf
  97.   \normalbaselineskip=12pt
  98.   \setbox\strutbox=\hbox{\vrule height8.5pt depth3.5pt width0pt}%
  99.   \normalbaselines\rm}
  100.  
  101. \parindent=30pt
  102. \def\inpar{\hangindent40pt\hangafter1\qquad}
  103. \def\onpar{\par\hangindent40pt\hangafter0}
  104.  
  105. \newskip\ttglue
  106. \ttglue=.5em plus.25em minus.15em
  107.  
  108. \def\orsign{$\mid\mid$}
  109.  
  110. \outer\def\begindisplay{\obeylines\startdisplay}
  111. {\obeylines\gdef\startdisplay#1
  112.   {\catcode`\^^M=5$$#1\halign\bgroup\indent##\hfil&&\qquad##\hfil\cr}}
  113. \outer\def\enddisplay{\crcr\egroup$$}
  114.  
  115. \chardef\other=12
  116.  
  117. \def\ttverbatim{\begingroup \catcode`\\=\other \catcode`\{=\other
  118.   \catcode`\}=\other \catcode`\$=\other \catcode`\&=\other 
  119.   \catcode`\#=\other \catcode`\%=\other \catcode`\~=\other 
  120.   \catcode`\_=\other \catcode`\^=\other
  121.   \obeyspaces \obeylines \tt}
  122. {\obeyspaces\gdef {\ }}
  123.  
  124. \outer\def\beginstt{$$\let\par=\endgraf \ttverbatim\ninett \parskip=0pt
  125.   \catcode`\|=0 \rightskip=-5pc \ttfinish}
  126. \outer\def\begintt{$$\let\par=\endgraf \ttverbatim \parskip=0pt
  127.   \catcode`\|=0 \rightskip=-5pc \ttfinish}
  128. {\catcode`\|=0 |catcode`|\=\other
  129.   |obeylines
  130.   |gdef|ttfinish#1^^M#2\endtt{#1|vbox{#2}|endgroup$$}}
  131.  
  132. \catcode`\|=\active
  133. {\obeylines\gdef|{\ttverbatim\spaceskip=\ttglue\let^^M=\ \let|=\endgroup}}
  134.  
  135. \def\beginlines{\par\begingroup\nobreak\medskip\parindent=0pt
  136.   \nobreak\ninepoint \obeylines \everypar{\strut}}
  137. \def\endlines{\endgroup\medbreak\noindent}
  138.  
  139. \def\<#1>{\leavevmode\hbox{$\langle$#1\/$\rangle$}}
  140.  
  141. \def\dbend{{$\triangle$}}
  142. \def\d@nger{\medbreak\begingroup\clubpenalty=10000
  143.   \def\par{\endgraf\endgroup\medbreak} \noindent\hang\hangafter=-2
  144.   \hbox to0pt{\hskip-\hangindent\dbend\hfill}\ninepoint}
  145. \outer\def\danger{\d@nger}
  146. \def\dd@nger{\medskip\begingroup\clubpenalty=10000
  147.   \def\par{\endgraf\endgroup\medbreak} \noindent\hang\hangafter=-2
  148.   \hbox to0pt{\hskip-\hangindent\dbend\kern 1pt\dbend\hfill}\ninepoint}
  149. \outer\def\ddanger{\dd@nger}
  150. \def\enddanger{\endgraf\endsubgroup}
  151.  
  152. \def\cstok#1{\leavevmode\thinspace\hbox{\vrule\vtop{\vbox{\hrule\kern1pt
  153.        \hbox{\vphantom{\tt/}\thinspace{\tt#1}\thinspace}}
  154.      \kern1pt\hrule}\vrule}\thinspace}
  155.  
  156. \newcount\exno
  157. \exno=0
  158.  
  159. \def\xd@nger{%
  160.   \begingroup\def\par{\endgraf\endgroup\medbreak}\ninepoint}
  161.  
  162. \outer\def\warning{\medbreak
  163.   \noindent\llap{$\bullet$\rm\kern.15em}%
  164.   {\ninebf WARNING}\par\nobreak\noindent}
  165. \outer\def\exercise{\medbreak \global\advance\exno by 1
  166.   \noindent\llap{$\bullet$\rm\kern.15em}%
  167.   {\ninebf EXERCISE \bf\the\exno}\par\nobreak\noindent}
  168. \def\dexercise#1{\global\advance\exno by 1
  169.   \medbreak\noindent\llap{$\bullet$\rm\kern.15em}%
  170.   #1{\eightbf ~EXERCISE \bf\the\exno}\hfil\break}
  171. \outer\def\dangerexercise{\xd@nger \dexercise{\dbend}}
  172. \outer\def\ddangerexercise{\xd@nger \dexercise{\dbend\dbend}}
  173.  
  174.  
  175. \newwrite\ans%
  176. \newwrite\conts%
  177.  
  178. \iffiles\else\outer\def\answer#1{\par\medbreak}\shutuptrue\fi
  179.  
  180. \newwrite\inx
  181. \ifshutup\else
  182. \immediate\openout\inx=$.games.infocom.ftp.toolkit.mandir.inxdata
  183. \fi
  184. \def\marginstyle{\sevenrm %
  185.   \vrule height6pt depth2pt width0pt } %
  186.  
  187. \newif\ifsilent
  188. \def\specialhat{\ifmmode\def\next{^}\else\let\next=\beginxref\fi\next}
  189. \def\beginxref{\futurelet\next\beginxrefswitch}
  190. \def\beginxrefswitch{\ifx\next\specialhat\let\next=\silentxref
  191.   \else\silentfalse\let\next=\xref\fi \next}
  192. \catcode`\^=\active \let ^=\specialhat
  193. \def\silentxref^{\silenttrue\xref}
  194.  
  195. \newif\ifproofmode
  196. \proofmodetrue %
  197.  
  198. \def\xref{\futurelet\next\xrefswitch}
  199. \def\xrefswitch{\begingroup\ifx\next|\aftergroup\vxref
  200.   \else\ifx\next\<\aftergroup\anglexref
  201.     \else\aftergroup\normalxref \fi\fi \endgroup}
  202. \def\vxref|{\catcode`\\=\active \futurelet\next\vxrefswitch}
  203. \def\vxrefswitch#1|{\catcode`\\=0
  204.   \ifx\next\empty\def\xreftype{2}%
  205.     \def\next{{\tt\text}}%
  206.   \else\def\xreftype{1}\def\next{{\tt\text}}\fi %
  207.   \edef\text{#1}\makexref}
  208. {\catcode`\|=0 \catcode`\\=\active |gdef\{}}
  209. \def\anglexref\<#1>{\def\xreftype{3}\def\text{#1}%
  210.   \def\next{\<\text>}\makexref} %
  211. \def\normalxref#1{\def\xreftype{0}\def\text{#1}\let\next=\text\makexref}
  212.  
  213. \def\makexref{\ifproofmode%
  214.   \xdef\writeit{\write\inx{\text\space!\xreftype\space
  215.     \noexpand\number\pageno.}}\iffiles\writeit\fi
  216.   \else\ifhmode\kern0pt \fi\fi
  217.  \ifsilent\ignorespaces\else\next\fi}
  218.  
  219. \newdimen\fullhsize
  220. \def\fullline{\hbox to\fullhsize}
  221. \let\lr=L \newbox\leftcolumn
  222.  
  223. \def\doubleformat{\shipout\vbox{\makeheadline
  224.     \fullline{\box\leftcolumn\hfil\columnbox}
  225.     \makefootline}
  226.   \advancepageno}
  227. \def\tripleformat{\shipout\vbox{\makeheadline
  228.     \fullline{\box\leftcolumn\hfil\box\midcolumn\hfil\columnbox}
  229.     \makefootline}
  230.   \advancepageno}
  231. \def\columnbox{\leftline{\pagebody}}
  232.  
  233. \newbox\leftcolumn
  234. \newbox\midcolumn
  235. \def\beginindex{
  236. \fullhsize=6.5true in \hsize=2.1true in
  237.  \global\def\makeheadline{\vbox to 0pt{\vskip-22.5pt
  238.       \fullline{\vbox to8.5pt{}\the\headline}\vss}\nointerlineskip}
  239.  \global\def\makefootline{\baselineskip=24pt \fullline{\the\footline}}
  240.  \output={\if L\lr
  241.    \global\setbox\leftcolumn=\columnbox \global\let\lr=M
  242.  \else\if M\lr
  243.    \global\setbox\midcolumn=\columnbox \global\let\lr=R
  244.  \else\tripleformat \global\let\lr=L\fi\fi
  245.  \ifnum\outputpenalty>-20000 \else\dosupereject\fi}
  246. \begingroup
  247.   \parindent=1em \maxdepth=\maxdimen
  248.   \def\par{\endgraf \futurelet\next\inxentry}
  249.   \obeylines \everypar={\hangindent 2\parindent}
  250.   \exhyphenpenalty=10000 \raggedright}
  251. \def\inxentry{\ifx\next\sub \let\next=\subentry
  252.   \else\ifx\next\endindex \let\next=\vfill
  253.   \else\let\next=\mainentry \fi\fi\next}
  254. \def\endindex{\mark{}\break\endgroup
  255. \supereject
  256. \if L\lr \else\null\vfill\eject\fi
  257. \if L\lr \else\null\vfill\eject\fi
  258. }
  259. \let\sub=\indent \newtoks\maintoks \newtoks\subtoks
  260. \def\mainentry#1,{\mark{}\noindent
  261.   \maintoks={#1}\mark{\the\maintoks}#1,}
  262. \def\subentry\sub#1,{\mark{\the\maintoks}\indent
  263.   \subtoks={#1}\mark{\the\maintoks\sub\the\subtoks}#1,}
  264.  
  265. \def\subsection#1{\medbreak\par\noindent{\bf #1}\qquad}
  266.  
  267. %  For contents
  268.  
  269. \def\cl#1#2{\bigskip\par\noindent{\bf #1}\quad {\bf #2}}
  270. \def\li#1#2#3{\smallskip\par\noindent\hbox to 5 in{{\bf #1}\quad #2\dotfill #3}}
  271. \def\sli#1#2#3{\par\noindent\hbox to 5 in{\qquad\item{#1}\quad #2\dotfill #3}}
  272. \def\fcl#1#2{\bigskip\par\noindent\hbox to 5 in{\phantom{\bf 1}\quad {\bf #1}\dotfill #2}}
  273.  
  274. % Epigrams
  275.  
  276. \def\poem{\begingroup\narrower\narrower\narrower\obeylines\ninepoint}
  277. \def\widepoem{\begingroup\narrower\narrower\obeylines\ninepoint}
  278. \def\verywidepoem{\begingroup\narrower\obeylines\ninepoint}
  279. \def\quote{\medskip\begingroup\narrower\narrower\noindent\ninepoint}
  280. \def\poemby#1#2{\par\smallskip\qquad\qquad\qquad\qquad\qquad -- #1, {\it #2}
  281. \tenpoint\endgroup\bigskip}
  282. \def\widepoemby#1#2{\par\smallskip\qquad\qquad\qquad -- #1, {\it #2}
  283. \tenpoint\endgroup\bigskip}
  284. \def\quoteby#1{\par\smallskip\qquad\qquad\qquad\qquad\qquad
  285.  -- #1\tenpoint\endgroup\bigskip}
  286. \def\endquote{\par\tenpoint\endgroup\medskip}
  287.  
  288. %
  289. %  End of macros
  290. \titletrue
  291.  
  292.  
  293. \centerline{\bigfont The Inform Designer's Manual}
  294. \vskip 0.5in
  295. \centerline{\sl Last updated 29/9/94}
  296. \vskip 0.5in
  297. \sli{}{Introduction}{2}
  298. \sli{1}{Getting started}{4}
  299. \sli{2}{Ingredients and lexicon}{7}
  300. \sli{3}{Objects, properties and attributes}{9}
  301. \sli{4}{Places, scenery and the map}{15}
  302. \sli{5}{Causing actions and making new ones}{18}
  303. \sli{6}{Containers, supporters and sub-objects}{22}
  304. \sli{7}{Doors}{23}
  305. \sli{8}{Switchable objects}{25}
  306. \sli{9}{Things to enter, travel in and push around}{26}
  307. \sli{10}{Living creatures and conversation}{27}
  308. \sli{11}{Starting, moving, changing and killing the player}{29}
  309. \sli{12}{Printing out names of objects}{31}
  310. \sli{13}{Classes of objects}{32}
  311. \sli{14}{Daemons and the passing of time}{34}
  312. \sli{15}{Adding verbs and grammar to the parser}{37}
  313. \sli{16}{Scope and what you can see}{44}
  314. \sli{17}{The light and the dark}{48}
  315. \sli{18}{On inventories and lists}{50}
  316. \sli{19}{The naming of names}{53}
  317. \sli{20}{Plural names and groups of similar objects}{55}
  318. \sli{21}{Miscellaneous constants and scoring}{57}
  319. \sli{22}{Debugging verbs and tracing}{59}
  320. \sli{23}{Limitations on the run-time format}{61}
  321. \sli{24}{A very few, not very special effects}{63}
  322. \sli{25}{Dirty tricks}{65}
  323. \sli{A1}{The Inform language}{67}
  324. \sli{A2}{Library objects, properties and attributes}{74}
  325. \sli{A3}{All the entry points, library routines and constants}{78}
  326. \sli{A4}{All the Inform error messages}{81}
  327. \sli{A5}{Compiler options and memory settings}{87}
  328. \sli{A6}{Answers to all the exercises}{91}
  329. \sli{A7}{Index}{102}
  330. \vfill\eject
  331. % --------------------------------------------------------------------------
  332. %     Body of text
  333. % --------------------------------------------------------------------------
  334. %$
  335. %$ This plain text version was generated automatically from the TeX
  336. %$ source, and is an approximate version of the typeset version.  In case
  337. %$ of garbled passages, consult that edition!
  338. %$
  339.  
  340. \section{}{Introduction}
  341.  
  342. \poem
  343. I will build myself a copper tower
  344. With four ways out and no way in
  345. But mine the glory, mine the power...
  346. \poemby{^{Louis MacNeice} (1907-1963)}{Flight of the Heart}
  347.  
  348. Inform is an Adventure-game compiler, and this is the book to read about it.
  349.  
  350. Infocom format `^{story files}' (Adventure games, that is) can be played on
  351. almost any computer, ancient or modern, and interpreters which run them are
  352. widely available, from personal organisers to mainframes.  They represent
  353. probably the most portable form in which games can ever be written, as no
  354. alteration whatever is required to move a game from one model of computer to
  355. another.
  356.  
  357. Inform is not just a compiler but an `operating system' too: its library (a
  358. suite of standard game routines) allows designers to begin coding at once. 
  359. An Inform source file need not contain any of the parser code, or the
  360. running of the `game universe', only descriptions and exceptions to the
  361. usual rules.  This world is quite rich already, having over 80 verbs and an
  362. extensive grammar: the library understands rooms, objects, duplicates,
  363. containers, doors, things on top of other things, light, scoring, switching
  364. things on and off, opening, closing and locking things, entering things,
  365. travelling about in them and so forth.  The parser it uses (which can be
  366. entirely invisible to the designer, but is programmable and very flexible)
  367. is sophisticated enough to handle ambiguities, clarify its input by asking
  368. questions and to cope properly with plurals, vagueness, conversation,
  369. pronouns and the player becoming someone else in mid-game.
  370.  
  371. This manual makes occasional reference to the example games provided with
  372. Inform, at present `Advent' (a full version of the original mainframe
  373. Adventure, which contains a good deal of `everyday Inform'), `Toyshop'
  374. (a collection of unusual objects to play with) and `Balances' (a short story
  375. consisting of puzzles making great use of the parser's flexibility).  Try
  376. to get hold of these programs and preferably print them out.  There is also
  377. a `Shell' game consisting of the minimum code to get going, but all 14
  378. lines of it are given in \S 1 anyway.
  379. \bigskip
  380.  
  381. The text of this book has evolved from five earlier editions.  The old
  382. manual was in places rather technical, with a makeshift and sometimes
  383. defensive tone (`Inform is an easel, not a painting').  There were
  384. specifications of the run-time code format and literary critiques of games
  385. gone by: like an oven manual padded out with both a cookery book and a
  386. detailed plan of the gas mains.  This book contains just the instructions
  387. for the oven.
  388.  
  389. So there are three ^{`companion volumes'}.  {\sl The Craft of Adventure} is
  390. an essay on the design of adventure games;  {\sl The Specification of the
  391. Z-Machine} covers the run-time format and Inform assembly language, its
  392. lowest level; and {\sl The Inform Technical Manual} documents chiefly
  393. internals, for compiler maintenance and porting.
  394.  
  395. In trying to be both a tutorial and reference work in a budget of about
  396. 100 pages of A4, this book aims itself in style halfway
  397. between the two extremes of manual, Tedium and Gnawfinger's ``Elements of
  398. Batch Processing in COBOL-66'', third edition, and Mr Blobby's ``Blobby Book
  399. of Computer Fun''.  (This makes some sections both leaden {\sl and}
  400. patronising.)  I have tried to make every passage tell the truth, so that
  401. even early sections are reliable for reference purposes.  Passages which
  402. divert the main story, usually to tell the unexpurgated truth when this may
  403. just confuse the newcomer, are marked with a warning triangle $\triangle$ or
  404. two, and set in smaller type.  Lengthy examples are left as exercises, with
  405. answers in the Appendix; which also contains a language specification, some
  406. reference lists, definitions of attributes and properties, and a large index.
  407.  
  408. \bigskip
  409. The copyright on Inform, the program and its source code, its example games
  410. and documentation (including this book) is retained by ^{Graham Nelson}, who
  411. asserts the moral right to be identified as its author.  Having said this, I
  412. am happy for it to be freely distributed to anybody who wants a copy,
  413. provided that: (a) distributed copies are not substantially different from
  414. those archived by the author, (b) this and other ^{copyright} messages are
  415. always retained in full, and (c) no profit is involved.  However, a story
  416. file produced with the Inform compiler (and libraries) then belongs to its
  417. author, and may be sold for profit if desired, provided that its game banner
  418. contains the information that it was compiled by Inform, and the Inform
  419. version number.
  420.  
  421. At present, the best source for Inform material (executables of the compiler
  422. for different machines, source code, the library files and example games) is
  423. the anonymous ftp site |ftp.gmd.de|, and its home directory is:
  424. \begintt
  425. if-archive/infocom/compilers/inform
  426. \endtt
  427.  
  428. Some of the ideas of Inform came from an incremental multi-player
  429. game called ^{Tera}, on the ^{Cambridge University} mainframe, written by
  430. Dilip Sequeira and the author in 1990 (whose compiler was called Teraform);
  431. in turn, this stole a little from ^{David Seal} and ^{Jonathan Thackray}'s
  432. game assembler; which dates back to the late 1970s and was written for
  433. ^{`Acheton'}, perhaps the first worthwhile game written outside America.
  434. Still, much of the Inform kernel derives ultimately from the {\sl IEEE Computer}
  435. article ``Zork: A Computerized Fantasy Simulation Game'' by P. David Lebling,
  436. Marc S. Blank and Timothy A. Anderson; and more was suggested by
  437. Richard Tucker, among others.
  438.  
  439. With the advent of Inform 5 in mid-1994, I feel that the underlying language
  440. came to a satisfactory state.  The library files, however, may well go on
  441. being improved, since users can update these much more easily than the
  442. compiler (changes to which mean work for many people).  The present
  443. library files (release 5/4) are greatly enhanced from the ^{Inform 5.2} files,
  444. but compatible with them (except in handling plural nouns and that the
  445. obselete attribute |autosearch| has been withdrawn).
  446.  
  447. The list of those who have helped the project along is legion: I should like
  448. to thank them all, porters, users and critics alike, but especially Volker
  449. Blasius, Paul David Doherty, Mark Howell, Bob Newell, Robert Pelak, Gareth
  450. Rees, J\o rund Rian, Dilip Sequeira, Richard Tucker and Christopher Wichura.
  451.  
  452. One final word.  I should like to dedicate this book, impertinently perhaps,
  453. to our illustrious predecessors: ^{Willie Crowther}, ^{Don Woods} and
  454. the authors of ^{Infocom, Inc.}
  455. \medskip
  456. %$                                                      Graham Nelson
  457. %$                                                      Magdalen College, Oxford
  458. %$                                                      September 1994
  459. %$-3
  460. \hbox to\hsize{\hfill\it Graham Nelson}
  461. \hbox to\hsize{\hfill\it Magdalen College, Oxford}
  462. \hbox to\hsize{\hfill\it September 1994}
  463. \vfill\eject
  464.  
  465. \section{1}{Getting started}
  466.  
  467. The first thing to try is to compile the ^{`Hello Cruel World'} game, a very
  468. short test file supplied with Inform.  If that compiles and runs properly
  469. (producing a short page of text, then finishing), try the following:^^{`Shell'}
  470. \begintt
  471. Constant Story "SHELL";
  472. Constant Headline "^An Interactive Skeleton^\
  473.              Copyright (c) 1994 by (your name here).^";
  474.  
  475. Include "Parser";
  476. Include "VerbLib";
  477.  
  478. Object Blank_Room "Blank Room"
  479.   with description "An empty room."
  480.   has  light;
  481.  
  482. [ Initialise;
  483.   location=Blank_Room;
  484.   "^^^^^Welcome to the shell...^^";
  485. ];
  486.  
  487. Include "Grammar";
  488. end;
  489. \endtt
  490. If this compiles, Inform is probably set up and working properly. It takes a
  491. short while to compile, because it `includes' three large standard files,
  492. containing a large amount of code.  (|Include| lines are also sometimes
  493. written |#include| to make C programmers feel more at home.)  The library
  494. files are:
  495. \medskip
  496. \settabs 6 \columns
  497. \+ & ^|Parser|  &  The core of the game, and a full parser\cr
  498. \+ & ^|VerbLib| &  Routines for many game verbs, like ``take''\cr
  499. \+ & ^|Grammar| &  A grammar table to decode the player's input from\cr
  500. \medskip\noindent
  501. Together, they make up the `library'.  They can certainly be modified by
  502. designers, but great effort has gone into making sure the need hardly ever
  503. arises.
  504.  
  505. \noindent Apart from that, the code contains:
  506. \item{(a)} strings giving the name of the game, and a copyright message, to be
  507. printed out at the appropriate moments;
  508. \item{(b)} a routine, called ^|Initialise|, which is run when the game begins,
  509. and simply sets where the player starts (in the obvious place!) and prints a
  510. welcoming message;
  511. \item{(c)} an object, to be the only room of the game.
  512. \par\noindent The `Shell' game is very boring: there is nothing for the player
  513. to do but wait and quit.
  514. \medskip
  515.  
  516. In Inform, everything is an object: rooms and things to be picked up,
  517. scenery, intangible things like mist and even some abstract ideas (like
  518. the direction `north').  More about this later: for now, here's a new
  519. object, to go under the |Blank_Room| definition:^^{green cone}
  520. \begintt
  521. Nearby cone "green cone"
  522.   with name "green" "cone";
  523. \endtt
  524. (|Nearby| just means it's an object inside the last thing declared as an
  525. |Object|, in this case the Blank Room.)  A green cone now appears in the
  526. Blank Room.  The player can call it either ``green cone", ``cone" or even
  527. ``green".  It can be taken, dropped, looked at, looked under and so on.
  528.  
  529. This is still rather plain.  Examining the cone sees ``nothing special about
  530. the green cone", for instance.  So we might extend the definition by:
  531. \begintt
  532. Nearby cone "green cone"
  533.   with name "green" "cone" "emerald",
  534.        initial "Nearby is an emerald green cone, one foot high.";
  535. \endtt
  536. The ^|initial| message now appears when we arrive in the Empty Room.  Taking
  537. things a little further...
  538. \begintt
  539. Nearby cone "green cone"
  540.   with name "green" "cone" "emerald" "marzipan",
  541.        initial "Nearby is an emerald green cone, one foot high.",
  542.        description "The cone seems to be made of emerald-coloured \ 
  543.                     marzipan."
  544.   has  edible;
  545. \endtt
  546. (Note that the description is split across two lines: the |\|
  547. makes the message
  548. come out as one sentence without a huge space.)  Now if we examine the
  549. cone, we get its surprising |description|: and the player is allowed to
  550. eat the cone.
  551.  
  552. \danger |name|, |description| and |initial| are examples of `properties',
  553. while |edible| is an `attribute': the difference is that the former have
  554. values, whereas the latter are just on or off.^^{properties}^^{attributes}
  555.  
  556. So far, we're just filling in a form, and we could go much further
  557. doing this, but that wouldn't be much of an example.  Instead, some
  558. honest programming:
  559. \beginstt
  560. Nearby cone "green cone"
  561.   with name "green" "cone" "emerald" "marzipan",
  562.        initial "Nearby is an emerald green cone, one foot high.",
  563.        description "The cone seems to be made of emerald-coloured \ 
  564.                     marzipan.",
  565.        after
  566.        [; Take: "Taken.  (Your hands are smeared with marzipan.)";
  567.           Drop: "The cone drops to the floor and sags a little.";
  568.        ],
  569.   has  edible;
  570. \endtt
  571. The property ^|after| doesn't just have a string for a value: it has a
  572. routine of its own.  Now what happens is that when an action happens
  573. to the cone, the |after| routine is called to apply any special rules
  574. about the cone.  In this case, |Take| and |Drop| are the only actions
  575. tampered with: and the only effect is that the usual messages
  576. (``Taken.'' ``Dropped.'') are replaced.
  577.  
  578. \danger There's no real difference between routines like |Initialise|,
  579. which are defined outside objects at the `top level', and routines
  580. inside objects like this |after| routine: except that outside routines
  581. have to have names, since they aren't identified by belonging to
  582. any particular object.
  583.  
  584. Still, the cone doesn't actually do anything!  So here it is with a
  585. (completely unfair) puzzle added:
  586. \beginstt
  587. Nearby cone "green cone"
  588.   with name "green" "cone" "emerald" "marzipan",
  589.        initial "Nearby is an emerald green cone, one foot high.",
  590.        description "The cone seems to be made of emerald-coloured \ 
  591.                     marzipan.",
  592.        before
  593.        [; Eat: if (random(100) <= 30)
  594.                {   deadflag = 1;
  595.                    "Unfortunately, you seem to be allergic to almonds.";
  596.                }
  597.                "You nibble at a corner of the cone.";
  598.        ],
  599.        after
  600.        [; Take: "Taken.  (Your hands are smeared with marzipan.)";
  601.           Drop: "The cone drops to the floor and sags a little.";
  602.        ],
  603.   has  edible;
  604. \endtt
  605. The |before| routine is called before the player's intended action takes
  606. place.  So when the player tries typing, say, ``eat the cone", what happens
  607. is: in 30\% of cases, she dies of ^{almond poisoning}; and in the other 70\%,
  608. she simply nibbles a corner of the cone (without actually consuming it
  609. completely).
  610.  
  611. \danger Like many programming languages, Inform braces together blocks of
  612. code.  ^|deadflag| is a global variable, whose value does not belong to any
  613. particular object (or routine).  It is defined somewhere in the depths of
  614. the library: it's usually 0; setting it to 1 causes the game to be lost,
  615. and setting it to 2 causes a win.
  616.  
  617. In either case, the usual rule for the |Eat| action is never applied.  This is
  618. because, although it isn't obvious from the code, the routine actually
  619. returns a value, true or false.  And the command
  620. \begintt
  621. "Unfortunately, you seem to be allergic to almonds.";
  622. \endtt
  623. not only prints the message (together with a carriage return), but also
  624. returns true from the ^|before| routine.  Since the routine normally returns
  625. false, the library knows that something has happened to interrupt the usual
  626. rules of the game.
  627.  
  628. \exercise  Extend the green cone so that it is described as sagging after
  629. it has been dropped back on the ground.  (You need a few more properties for
  630. this.)
  631.  
  632. \answer{\beginlines
  633. |Nearby cone "green cone"|
  634. |  with name "green" "cone" "emerald" "marzipan",|
  635. |       describe|
  636. |       [; if (cone has moved)|
  637. |              "A misshapen cone of green marzipan sits here.";|
  638. |          "Nearby is an emerald green cone, one foot high.";|
  639. |       ],|
  640. |       description "The cone seems to be made of emerald-coloured \ |
  641. |                    marzipan.",|
  642. |       before|
  643. |       [; Eat: if (random(100) <= 30)|
  644. |               {   deadflag = 1;|
  645. |                   "Unfortunately, you seem to be allergic to almonds.";|
  646. |               }|
  647. |               "You nibble at a corner of the cone.";|
  648. |       ],|
  649. |       after|
  650. |       [; Take: "Taken.  (Your hands are smeared with marzipan.)";|
  651. |          Drop: cone.description = "The cone is a vague green mess.";|
  652. |                "The cone drops to the floor and sags a little.";|
  653. |       ],|
  654. |  has  edible;|
  655. \endlines
  656. The old |initial| message has gone.  Instead, we have provided a
  657. |describe| routine.  Whenever the game has to describe the cone in the
  658. description of a place, it will call this routine.  The |moved| attribute
  659. is held only by an object which has at some time in the past been taken.  So
  660. the cone is now perfect and untouched until taken and dropped, whereupon
  661. it becomes misshapen.  Also, the act of dropping the cone now changes the
  662. description which appears when a player examines it.}
  663.  
  664.  
  665. \section{2}{Ingredients and lexicon}
  666.  
  667. Properly speaking, `Inform' means the compiler and its language: whereas this
  668. book is chiefly about the `library' of code which comes with it.  For
  669. most practical purposes this makes no difference - but it's worth remembering
  670. that in the last resort you can change almost anything about how the ^{library}
  671. works.
  672.  
  673. The basic ingredients of an Inform game are:
  674. \begindisplay
  675. {\bf Objects},\quad {\bf Routines},\quad {\bf Actions}\quad {\rm and}\quad {\bf Grammar}.
  676. \enddisplay^^{lexicon}^^{actions}
  677. We have already seen examples of Objects and Routines.  Actions happen in the
  678. course of play.  The main loop of a game looks like this:
  679. \medskip
  680. \item{1.}{Ask the player to type something}
  681. \item{2.}{Parse this (i.e. decide what it means) and generate any actions it
  682. calls for}
  683. \item{3.}{Work out the consequences of these actions and tell the player}
  684. \item{4.}{Worry about time passing by, and other things happening}
  685. \medskip\noindent
  686. a process which ends only in victory or death.  (In this respect it is unlike
  687. life.)
  688.  
  689. Probably the most complicated programming in any adventure game goes into the
  690. parser.  Inform's parser is fairly advanced, and is designed with the intention
  691. of being highly programmable at all levels to suit your game: so this manual
  692. will be returning to features of the parser again and again.  It isn't perfect
  693. by any means, but it does understand things like:
  694. \begintt
  695. throw three of the coins into the fountain
  696. write funny on the lighted cube
  697. take the sword and all the crowns
  698. what is a grue
  699. dwarf, give me the battleaxe
  700. \endtt
  701. It also asks questions when it needs to, makes inferences from partial requests
  702. and tries to make good guesses when faced with ambiguous requests.  You can
  703. teach it new verbs and new forms of old ones: this is ^{Grammar}.  (The library
  704. starts with about 85 verbs, not counting synonyms.)
  705.  
  706. Until you need to start programming it, the parser sits in the background, and
  707. you need to know nothing about it.  But the parser is where Actions come from.
  708. An Action can have up to two objects attached to it, and represents something
  709. which the player is trying to do.  For instance,
  710. \begindisplay
  711. |Inv| \qquad |Take sword|\qquad |Insert gold_coin cloth_bag|
  712. \enddisplay
  713. are all actions.  (By this stage the game has reduced them to three numbers
  714. each, the action number and two object numbers: there's no text floating about.)
  715.  
  716. \danger Actions are also sometimes produced as a knock-on effect by other
  717. actions, and they can also be produced by your own code: you can even create
  718. new actions altogether, which are treated no differently from the standard ones.
  719.  
  720. \exercise Compile one of the supplied example games, say `Toyshop', with
  721. the ^|DEBUG| option defined (see the section on debugging) so that you can use
  722. the special ^{``actions'' verb} to see exactly what all the actions are as they
  723. happen.
  724.  
  725. \answer{You may be surprised how many actions take place: often more than one
  726. per turn.}
  727.  
  728. \bigskip
  729. \danger Inform can produce two kinds of game: ``Standard'' and ``Advanced''.
  730. ^^{Standard games}^^{Advanced games}
  731. Code is in almost every case portable between these two forms, so that you
  732. can easily make a version each way from the same program.  The latter is
  733. better, but just in case you have a small computer (such as a personal
  734. organiser) or a very bad run-time interpreter, you might prefer the former.
  735. Occasionally this manual will mention a difference between these forms.
  736.  
  737. \ddanger At this point, we should describe the imaginary machine, sometimes
  738. called the Z-machine (Z is for ^{`Zork'}) which Inform compiles games for.
  739. An `interpreter' is a program which simulates this imaginary machine, so that
  740. it can run the game files that Inform produces: the same files will work
  741. on any ^{interpreter} on any machine.  Interpreters are available for very many
  742. machines indeed.  The ^{Z-machine} is, except in a few corners, a beautiful
  743. design and is described in great detail in the {\sl Specification of the
  744. Z-Machine}.  For now, a few words about the ^{memory map}.  The memory of
  745. this imaginary computer is 128K long for Standard games and 256K long for
  746. advanced ones: the format is extremely well compressed, so this is actually
  747. quite a large memory.
  748.  
  749. \ddanger Numbers are stored in 16-bit words (2 bytes long), and are signed
  750. in the usual way, so they hold values^^{numbers}
  751. $$ -32768 \leq n\leq 32767 $$
  752. with the hexadecimal value |$ffff| being the same as $-1$.  The sign doesn't
  753. mean anything for ^{addresses}, of course, but there's a catch: given that a
  754. 2-byte number can only hold a value $0\leq n\leq 65535$, how can an address
  755. in a 128K or 256K memory map be held?  The answer is that there are two
  756. kinds of address: a `packed address' and a `byte address'.  A ^{byte address} is
  757. just an address in the bottom 64K of memory, and the Z-machine is arranged
  758. so that everything which could ever change is there: so these are the only
  759. addresses which matter very much.  Packed addresses are addresses divided
  760. by 2 (or by 4 in Advanced games), so they can only refer to even (divisible
  761. by four) locations in memory.  They hold the addresses of long strings and
  762. routines, which Inform is careful always to put at even (divisible by four)
  763. locations.^^{packed address}
  764.  
  765. \vfill\eject
  766. \section{3}{Objects, properties and attributes}
  767.  
  768. \quote
  769. Objects make up the substance of the world.  That is why
  770. they cannot be composite.
  771. \poemby{Ludwig Wittgenstein (1889-1951)}{Tractatus}
  772.  
  773. \quote
  774. ...making philosophical sense of change runs up against what
  775. seem to be impossible philosophical difficulties.  Aristotle...
  776. focuses on the central case of an object coming to have a
  777. property that it formerly lacked.
  778. \poemby{Julia Annas}{Classical Greek Philosophy}^^{Aristotle}
  779.  
  780.  
  781. The ^{objects} of the game form what is sometimes called a `tree', though
  782. a better analogy would be a forest, and anyway one usually draws the whole
  783. thing upside down and uses the language of `families' - calling them `children'
  784. and `parents' of each other.  Anyway, here's an example:^^{tree of objects}
  785.  
  786. %$-9
  787. \def\ra{\rightarrow}\def\da{\downarrow}
  788. $$\matrix{
  789. |Meadow|\cr
  790.   \da\cr
  791. |Mailbox| & \ra & |Player|\cr
  792.   \da     &     &   \da\cr
  793.  |Note|   &     & |Sceptre| & \ra & |Cucumber| & \ra & |Torch| & \ra & |Magic Rod|\cr
  794.           &     &           &     &            &     &   \da\cr
  795.           &     &           &     &            &     & |Battery|\cr} $$
  796. %$    Meadow
  797. %$      |
  798. %$    Mailbox  ->  Player
  799. %$      |            |
  800. %$     Note        Sceptre   ->   Cucumber  ->   Torch  ->   Magic Rod
  801. %$                                                 |
  802. %$                                               Battery
  803.  
  804. This is a family tree, then: each object has a parent, a sibling and a child,
  805. though that object may be the special |nothing| object.  (The |Cucumber| has
  806. child |nothing|, for instance.)
  807.  
  808. As the game goes on, objects move around: when an object moves, all its
  809. possessions (that is, children) go with it.  The Inform command to move an
  810. object is^^|move|
  811. \begintt
  812. move object to new-owner;
  813. \endtt
  814. and it must be emphasized that this prints nothing on the screen, and indeed
  815. does nothing except to change the tree above.
  816.  
  817. Inform provides special functions for reading this tree.
  818. \begindisplay
  819. ^|parent|,\quad ^|sibling|\quad and\quad ^|child|
  820. \enddisplay
  821. all do the obvious things, and in addition there's a function called |children|
  822. which counts up how many children an object has (only children: grandchildren
  823. aren't counted).  For instance,
  824. \begintt
  825.  parent ( Mailbox ) = Meadow
  826.  children ( Player ) = 4
  827.  child ( Sceptre ) = 0
  828.  sibling ( Torch ) = Magic Rod
  829. \endtt
  830. \danger ^|nothing| isn't really an object: it's just a convenient name for the
  831. number 0, which is the object number meaning `no such object'.  It isn't a good
  832. idea to meddle with |nothing|, or to apply functions like |parent| to it,
  833. but then there's never any need.
  834.  
  835. \ddanger When an object is added to the possessions held by another, it appears
  836. at the end of the list.  Thus, the eldest child is first in the list and the
  837. youngest is last.  Inform also provides functions
  838. \smallskip\ninepoint
  839. \settabs 5 \columns
  840. \+ &^|youngest| & end of list of possessions\cr
  841. \+ &^|eldest|   & same as |child|\cr
  842. \+ &^|younger|  & same as |sibling|, i.e. rightwards in the picture\cr
  843. \+ &^|elder|    & reverse of |sibling|, i.e. leftwards in the picture\cr
  844. \smallskip\tenpoint
  845.  
  846. Objects have more to them than just where they are in the tree.  They
  847. also have collections of variables attached to them.
  848.  
  849. Firstly, there are ^{flags}, called ``^{attributes}'', which can be either set or
  850. clear.  These might be such conditions as ``giving light", ``currently worn"
  851. or ``is one of the featureless white cubes".  Attributes all have names,
  852. which are a single word: like ^|light|, for instance, which indicates that
  853. something is giving off light.  There are about 30 defined by the library.
  854. They can be tested with a condition like^^|has|
  855. \begintt
  856. if (obj has locked) "But it's locked!";
  857. \endtt
  858. and can be set with the ^|give| command.  So, for instance,
  859. \begintt
  860. give brass_lantern light;
  861. give iron_door locked;
  862. \endtt
  863. and they can be taken away with
  864. \begintt
  865. give brass_lantern ~light;
  866. give fake_coin ~scored;
  867. \endtt
  868. the |~| sign (or tilde) standing for negation.  In fact you can give or take
  869. many at one go, so for instance
  870. \begintt
  871. give wooden_door open openable ~locked;
  872. \endtt
  873. \danger You can make your own attributes
  874. ^^{making attributes}
  875. with a directive like
  876. \begintt
  877. Attribute offered_to_ogre;
  878. \endtt
  879. at the start of the program.  (A `^{directive}' is a command to Inform directly,
  880. and happens at compile-time: not something in a routine which is to happen in
  881. the course of play.)
  882.  
  883. \ddanger In ^{Standard games} there are few spare attributes available because
  884. th library takes most of them.  To get around this limit
  885. there's a convenient dodge.  It sometimes happens that an attribute is only
  886. meaningful for a particular kind of object: for instance, ``spell has been
  887. read" might only be meaningful for a ``scroll".  With care, therefore, one
  888. may re-use the same attribute to have different meanings for different kinds
  889. of object. The syntax to declare that an attribute is being reused is
  890. ^^|alias|^^{reusing attributes}^^|Attribute|
  891. \begintt
  892. Attribute <new> alias <old>;
  893. \endtt
  894. Thereafter Inform will treat the new and old attribute names as
  895. referring to the same attribute: it's up to the programmer to make sure this
  896. does not lead to inconsistencies.  (The library already indulges in a certain
  897. amount of this chicanery.)
  898.  
  899. \medskip
  900. Secondly, there are ``^{properties}''.  These are far more elaborate, and not
  901. every object has every property.  For instance: not every object has the
  902. |door_to| property (it holds the place a door leads to, so things other
  903. than doors don't usually have it).  The current value of a property is
  904. got at by constructions like:
  905. \begintt
  906. iron_door.door_to
  907. crystal_bridge.door_to
  908. green_cone.before
  909. diamond.initial
  910. \endtt
  911. You can read the value of |door_to| for something like the |diamond|,
  912. and you'll just get a dull value like |nothing|, but you can't write to it:
  913. that is, you can't change |diamond.door_to| unless you declared a |door_to|
  914. property for it.
  915.  
  916. \danger You can also define your own properties (again, subject to
  917. availability, because the library claims many of them).^^{making properties}
  918. \begintt
  919. Property door_to;
  920. Property article "a";
  921. Property blorple_routine $ffff;
  922. \endtt
  923. are all examples of the ^|Property| directive.  In the case of |article|,
  924. we are saying that the value |"a"| should be the default value for any
  925. object which doesn't declare an |article|.^^{default value of properties}
  926.  
  927. \ddanger Properties can also ^|alias|.  They can also be declared as
  928. ^|long| or ^|additive|, which is a complicated matter: basically, we'll
  929. come to |additive| when discussing classes, and properties which might
  930. start as small numbers (less than 256) and be changed into large ones
  931. in play, ought to be declared as |long|.
  932.  
  933. As will be seen from examples, a property value can be many things:
  934. a string like |"frog"|, a number such as |$ffff| (this is the Inform
  935. way of writing numbers in ^{hexadecimal}), an object or a routine.  You
  936. can change the current value by something like
  937. \begintt
  938. location.door_to = hall_of_mists;
  939. brass_lantern.short_name = "dimly lit brass lantern";
  940. grenade.time_left = 45;
  941. \endtt
  942.  
  943. \warning The game may crash at run-time if you attempt to write to a property
  944. field which an object hasn't got.  So although you can read an undeclared
  945. property (you just get the default value), you can't write to one.
  946. (Also, you can't extend a property beyond its length: see below.)
  947.  
  948. \danger The Inform language does not have types as such, and strings
  949. and routines are stored as numbers: as their addresses inside the virtual
  950. machine, in fact.  This means that Inform thinks
  951. \begintt
  952. "Hello there" + 45 + 'a'
  953. \endtt
  954. is a ^{perfectly sensible} calculation.  It's up to you to be careful.
  955. ^^{types (lack of)}
  956.  
  957. \ddanger A property can hold more than just one number (be it interpreted
  958. as a string, a routine or whatever): it can hold a ^{small array} of numbers.
  959. In ^{Standard games} it can have four numbers (8 bytes' worth), and in
  960. ^{Advanced games} 32 (64 bytes).  For instance, an entry in an object
  961. definition might read
  962. \begintt
  963.  found_in  Marble_Hall  Arched_Passage  Stone_Stairs,
  964. \endtt
  965. storing a sequence of three values (all objects) in the |found_in|
  966. ^^|found in|
  967. property.
  968. To read or write to this array, you need to know its (byte) address and its
  969. length.  The operators
  970. \begindisplay
  971. |object.&property|\quad and\quad |object.#property|
  972. \enddisplay
  973. tell you these.  (Be warned: |object.#property| tells you the number of bytes,
  974. not the number of words.)
  975. If you give a property more than 8 bytes of data in a Standard game,
  976. Inform warns you and takes only the first 8, but does not cause an
  977. error: this is so that, say,
  978. \beginstt
  979. Object ...
  980. with name "radio" "wireless" "transistor" "portable" "stereo" "tranny",
  981.      ...
  982. \endtt
  983. will compile either way (but the last two synonyms for |"radio"| will not
  984. enter the dictionary if it's being compiled in Standard form, since a name
  985. takes two bytes).
  986.  
  987.  
  988. \ddangerexercise Use the |object.&property| construction to find out whether
  989. the object in variable |obj| has the |door_to| property defined or not.
  990.  
  991. \answer{|if (obj.&door_to == 0) { ... }|}
  992.  
  993. \bigskip\noindent
  994. Time to make some ^{object definitions}.  A typical object definition looks
  995. something like:
  996. \beginstt
  997. Object trapdoor "hinged trapdoor" attic
  998.   with name "hinged" "trap" "door" "trapdoor",
  999.        when_open "A hinged trapdoor in the floor stands open, and light \
  1000.                   streams in from below.",
  1001.        when_closed "There is a closed trapdoor in the middle of the floor.",
  1002.        door_to house,
  1003.        door_dir d_to,
  1004.   has  door static open light openable;
  1005. \endtt
  1006. This is the conventional way to lay out an ^|Object| declaration: with the
  1007. header first, then ^|with| a list of properties and their starting values,
  1008. finishing up with the attributes it initially ^|has|.
  1009.  
  1010. |trapdoor| is the name given to the object in the program, and it becomes
  1011. a constant from then on (whose value is the number of the object).  The
  1012. |attic| is the object which the |trapdoor| starts out belonging to (as
  1013. any player of ^{`Curses'} will know).  Some objects start out not
  1014. belonging to anything (rooms, for example, or treasures which only appear
  1015. half-way through).  You can declare these as belonging to |nothing|, but
  1016. it's better just to miss this out altogether:
  1017. \begintt
  1018. Object trapdoor "hinged trapdoor"
  1019.   with ...
  1020. \endtt
  1021. If you do declare an object already belonging to another, as above,
  1022. then the other object must already have been defined.  (This is no real
  1023. restriction, and ensures that you can't set up a `loop' - one in another
  1024. in a third in the first, for instance.)
  1025.  
  1026. Objects can also be declared, in an identical way, by the |Nearby| directive.
  1027. The only difference is that no initial-owner object can be given; it starts
  1028. out belonging to the last thing declared as an |Object|.  For example, in
  1029. \begintt
  1030. Object hillside "Panoramic Hillside"
  1031.   with ...
  1032.  
  1033. Nearby scenery "scenery"
  1034.   with ...
  1035. \endtt
  1036. the |hillside| is a room to which the |scenery| will belong.  Otherwise,
  1037. ^|Nearby| is the same as |Object|, and this is just a convenience to make
  1038. it easier to move things around in Inform code by cutting definitions out
  1039. and pasting them in elsewhere.
  1040.  
  1041. Some properties of objects should be routines.  For instance,
  1042. an object can have a ^|describe| property which is a routine to print out
  1043. a description of it.
  1044.  
  1045. These could just be listed as names of routines, but usually the actual
  1046. routine is written out then and there as the property value.
  1047. For instance, in the classic Adventure object^^{tasty food}
  1048. \begintt
  1049. Nearby tasty_food "tasty food"
  1050.       with description "Sure looks yummy!",
  1051.                initial "There is tasty food here.",
  1052.            name "food" "ration" "rations" "tripe"
  1053.                 "yummy" "tasty" "delicious" "scrumptious",
  1054.            after
  1055.            [; Eat: "Delicious!"; ],
  1056.            article "some"
  1057.       has  edible;
  1058. \endtt
  1059. the |after| property does not name a routine but instead defines it.  No
  1060. name is needed or given for the routine.  (The semicolon after the |[| is
  1061. needed to show that the routine has no local variables.)
  1062.  
  1063. The routine must end with either |],| or |];|.  If |],| the object definition
  1064. can resume where it left off, with further properties.  (If it ends with
  1065. |];|, then the object definition ends where the routine finishes.)
  1066.  
  1067. \danger The rules for ^{embedded routines} are not quite the same as those
  1068. for ordimary routines.  By default, embedded routines return ``false", or 0
  1069. (instead of ``true", or 1, which other routines return by default).  Also,
  1070. the handy shorthand:
  1071. \begintt
  1072. Action [, Action2 ...] : ...some code...
  1073. \endtt
  1074. is provided, which executes the code only if the action being considered
  1075. is the one named.
  1076.  
  1077. \ddanger It actually does this by setting a special variable called
  1078. |sw__var|
  1079. ^^|sw  var|
  1080. to the action number: when it compiles |Action1:| it just
  1081. compiles an |if| statement which sees whether |sw__var| has value |Action1|.
  1082.  
  1083. \danger Properly speaking, the full syntax of the header is^^{Object syntax}
  1084. \begindisplay
  1085. |Object| \<obj-name-1> \<obj-name-2> ... \<obj-name-$n$> |"short name"|
  1086. |[|\<parent-obj>|]|\cr
  1087. {\it or}\quad |Nearby| \<obj-name-1> \<obj-name-2> ... \<obj-name-$n$>
  1088. |"short name"|\cr
  1089. {\it or}\quad |Class| \<class-name>\cr
  1090. \enddisplay
  1091. and the parent object must have already been defined.
  1092. A ^|Class| definition is very like an object definition, and will be discussed
  1093. later on.  The syntax for an object, then, is
  1094. \begindisplay
  1095. \<Header> |[,]|\cr
  1096. \quad |class| \<class-1> \<class-2> ... \<class-$n$> |[,]|\cr
  1097. \quad |with|  \<property-name-1> \<value-1> ... \<value-$n$>|,|\cr
  1098. \qquad        \<property-name-2> \<value-1> ... \<value-$n$>|,|\cr
  1099. \qquad        ...\cr
  1100. \qquad        \<property-name-$n$> \<value-1> ... \<value-$n$> |[,]|\cr
  1101. \quad |has|  \<att-1> \<att-2> ... \<att-$n$>\cr
  1102. \enddisplay
  1103. Although it's conventional to write ^|class|, |with| and |has| in this order,
  1104. actually they can be in any order and any or all can be omitted altogether:
  1105. and the commas in square brackets |[,]| are optional in between these fields.
  1106. (The classes listed under |class| are those which the object inherits from.)
  1107.  
  1108. \danger One property is treated differently from the others, and this
  1109. is the special property ^|name|.  Its data must be a list of English words
  1110. in double-quotes, as in all the above examples.  (Probably the most
  1111. annoying restriction of ^{Standard games} is that this means only 4 names
  1112. at most can be accommodated in that format: you get up to 32 in ^{Advanced
  1113. games}.)  It will probably confuse the parser if any of these names is
  1114. something like |"my"|, |"the"|, |"all"|, |"except"| or |"this"|.  Numbers
  1115. can safely be used, however.
  1116.  
  1117. \ddanger In fact, ^|name| contains a list of byte addresses of dictionary
  1118. words.  A quick way to print out the first word in the |name| list is
  1119. therefore
  1120. \begintt
  1121. print_addr obj.name;
  1122. \endtt
  1123.  
  1124. \ddanger The attributes \<att-1> and so on can be taken away as well as
  1125. added, thus:
  1126. \begintt
  1127.   ...
  1128.   has  light ~scored;
  1129. \endtt
  1130. which is sometimes useful to over-ride an ^{inheritance} from a class definition.
  1131.  
  1132. \ddanger A final curiosity of the |Object| syntax is that objects can be given
  1133. more than one name.  This is a ^{hangover} from much earlier days of Inform,
  1134. to do with re-using the same physical object in different logical ways,
  1135. something which the author does not commend to anyone.
  1136.  
  1137. \section{4}{Places, scenery and the map}
  1138.  
  1139. \quote
  1140. It was a long cylinder of parchment, which he unrolled and spread out
  1141. on the floor, putting a stone on one end and holding the other.
  1142. I saw a drawing on it, but it made no sense.
  1143. \poemby{^{John Christopher}}{The White Mountains}
  1144.  
  1145. \poem
  1146. And if no piece of chronicle we prove,
  1147. We'll build in sonnets pretty rooms;
  1148. As well a well wrought urn becomes
  1149. The greatest ashes, as half-acre tombs.
  1150. \poemby{^{John Donne} (1571?-1631)}{The Canonization}
  1151.  
  1152. Back to our example.  Throw away the old ``blank room" and replace it by...
  1153. \beginstt
  1154. Object Square_Room "Square Room"
  1155.   with description
  1156.        "A broad, square room, ten yards on a side, floored \
  1157.        with black and white chequered tiles."
  1158.   has  light;
  1159. \endtt
  1160. ^^{Square Room}
  1161. (We also have to change the |Initialise| routine to make this the place
  1162. where the player begins, since the Blank Room no longer exists.)
  1163.  
  1164. Like the blank room, this one has |light|.  (If it didn't, the player
  1165. would never see it, since it would be dark, and the player hasn't yet
  1166. been given a lamp or torch of some kind.)  So where is the light coming
  1167. from?
  1168. \beginstt
  1169. Nearby chandelier "crystal chandelier"
  1170.   with name "crystal" "chandelier",
  1171.        initial "A crystal chandelier hangs from far above, casting \
  1172.                 light in little rainbows across the floor.",
  1173.        description "The crystal is beautiful cut-glass."
  1174.   has  static;
  1175. \endtt
  1176. ^^{crystal chandelier}
  1177. This is part of the fittings, hence the |static| attribute (which means it
  1178. can't be taken or moved).  But what about the rainbows?
  1179. \beginstt
  1180. Nearby rainbows "rainbows"
  1181.   with name "rainbow" "rainbows",
  1182.        description "Caused by diffraction, or something like that - \
  1183.                     you were never very good at physics."
  1184.   has  scenery;
  1185. \endtt
  1186. ^^{rainbows}
  1187. Being ^|scenery| makes the object not only static but also not described
  1188. by the game unless actually examined by the player.  A true perfectionist
  1189. might alter it to:
  1190. \beginstt
  1191. Nearby rainbows "rainbows"
  1192.   with name "rainbow" "rainbows",
  1193.        description "Caused by diffraction, or something like that - \
  1194.                     you were never very good at physics.",
  1195.        before
  1196.        [; Take, Push, Pull, Turn: "But the rainbows are made of light.";
  1197.        ],
  1198.   has  scenery;
  1199. \endtt
  1200. Let us now add a second room:
  1201. \beginstt
  1202. Object Corridor "Sloping Corridor"
  1203.   with description
  1204.            "This corridor slopes upward and out of the square room.",
  1205.        d_to Square_Room, s_to Square_Room,
  1206.        u_to "The slope becomes impossibly steep, and you retreat.",
  1207.        cant_go "The corridor runs up and down."
  1208.   has  light;
  1209. \endtt
  1210. ^^{Sloping Corridor}
  1211. and extend the Square Room to:
  1212. \beginstt
  1213. Object Square_Room "Square Room"
  1214.   with description
  1215.           "A broad, square room, ten yards on a side, floored \
  1216.            with black and white chequered tiles.  A doorway in the \
  1217.            centre of the north side opens onto a rising corridor.",
  1218.        u_to Corridor,
  1219.        n_to Corridor
  1220.   has  light;
  1221. \endtt
  1222. The player can now go from one to the other.  The properties |u_to|, |d_to|,
  1223. |n_to| (and so on) declare what lies in the
  1224. ^{directions} ``up", ``down", ``north"
  1225. (and so on).  If they aren't declared, one cannot go that way.  Notice that
  1226. they can be either a room or a message which is printed if the player tries
  1227. to go in the given direction.
  1228. ^^{map}
  1229.  
  1230. In the Square Room, if the player tries to go, say, east, she gets a message
  1231. along the lines of ``You can't go that way.", which is not very helpful.  In
  1232. the Corridor, the |cant_go|
  1233. ^^|cant go|
  1234. message is printed instead.  (In fact, as is often the case with properties,
  1235. instead of giving an actual message you can instead give a routine to print
  1236. one out, so that what is printed varies with circumstances.)
  1237.  
  1238. Map connections are all one-way, in themselves: they just happen to be
  1239. defined here so that they appear two-way.
  1240. \bigskip
  1241.  
  1242. Rooms also have rules of their own.  We might write:
  1243. \beginstt
  1244. Object Corridor "Sloping Corridor"
  1245.   with description
  1246.           "This corridor slopes upward and out of the square room:  \
  1247.            the floor underfoot is a little sticky.",
  1248.        d_to Square_Room, s_to Square_Room,
  1249.        u_to "The slope becomes impossibly steep, and you retreat.",
  1250.        cant_go "The corridor runs up and down.",
  1251.        before
  1252.        [; Take: if (noun == cone)
  1253.                    "The cone seems to be stuck to the floor here.";
  1254.        ],
  1255.   has  light;
  1256. \endtt
  1257. and now the cone (if dropped there) cannot be taken from the floor of
  1258. the Sloping Corridor.  The variables |noun| and |second| hold the first
  1259. and second nouns supplied with an action.  Rooms have |before| and |after|
  1260. routines just as objects do.
  1261.  
  1262. \ddanger Sometimes the room may be a different one after the action has
  1263. taken place.  The ^|Go| action, for instance, is offered to the |before|
  1264. routine of the room which is being left, and the ^|after| routine of the
  1265. room being arrived in.  For example:
  1266. \beginstt
  1267.        after
  1268.        [; Go: if (noun==in_obj)
  1269.               print "How grateful you are to get out of the rain...^";
  1270.        ],
  1271. \endtt
  1272. will print the message when the room is entered via the ``in" direction.
  1273. (Note that the message is printed with the ^|print| command.  This means
  1274. that it does not automatically return true: in fact, it returns false,
  1275. so the game knows that the usual rules still apply.  Also, no new-line
  1276. is printed automatically: but the |^| symbol means ``print a new-line",
  1277. so one is actually printed.)
  1278.  
  1279. \danger Directions (such as ``north") are objects called |n_obj|, |s_obj|
  1280. and so on: in this case, |in_obj|.  (They are not to be confused with the
  1281. property names |n_to| and so on.)  Moreover, you can change these
  1282. directions (as far as Inform is concerned, only things in the special
  1283. object |compass| can be directions).
  1284.  
  1285. \dangerexercise In the first millenium A.D., the Mayan peoples of the
  1286. Yucat\'an Peninsula had `world colours' white ({\it sac}), red ({\it chac}),
  1287. yellow ({\it kan}) and black ({\it chikin}) for what we call the compass
  1288. bearings north, east, south, west (for instance west is associated
  1289. with `sunset', hence black, the colour of night). Implement this.^^{world
  1290. colours}^^{Mayan directions}^^{direction objects}
  1291.  
  1292. \answer{Define four objects along the lines of:
  1293. \beginlines
  1294. |Object white_obj "white wall" compass|
  1295. |  with name "white" "sac" "wall", article "the", door_dir n_to|
  1296. |  has  direction scenery;|
  1297. \endlines^^{world colours}^^{Mayan directions}^^{direction objects}
  1298. and add the following line to |Initialise|:
  1299. \beginlines
  1300. |remove n_obj; remove e_obj; remove w_obj; remove s_obj;|
  1301. \endlines
  1302. (We could even |alias| a new property |white_to| to be |n_to|, and then
  1303. enter map directions in the source code using Mayan property names.)
  1304. As a fine point of style, turquoise ({\it yax}) is the world colour for
  1305. `here', so add a grammar line to make this cause a ``look'':
  1306. \beginlines
  1307. |Verb "turquoise" "yax" * -> Look;|
  1308. \endlines}
  1309.  
  1310. \dangerexercise (Cf. ^{`Trinity'}.)  How can the entire game map
  1311. be suddenly east-west reflected?^^{reflecting the map}
  1312.  
  1313. \answer{^^{reflecting the map}\beginlines
  1314. |[ SwapDirs o1 o2 x;|
  1315. |  x=o1.door_dir; o1.door_dir=o2.door_dir; o2.door_dir=x; ];|
  1316. |[ ReflectWorld;|
  1317. |  SwapDirs(e_obj,w_obj); SwapDirs(ne_obj,nw_obj); SwapDirs(se_obj,sw_obj);|
  1318. |];|
  1319. \endlines}
  1320.  
  1321. \ddangerexercise  Even when the map is reflected, there may be many
  1322. room descriptions referring to ``east'' and ``west'' by name.  Reflect
  1323. these too.
  1324.  
  1325. \answer{This is a prime candidate for using ^{variable strings}
  1326. ^|@nn|, a topic properly covered in the {\sl Inform Technical Manual},
  1327. but briefly: at the head of the source, define
  1328. \beginlines
  1329. |Lowstring east_str "east"; Lowstring west_str "west";|
  1330. \endlines^^|Lowstring|^^|String|
  1331. and then add two more routines to the game,
  1332. \beginlines
  1333. |[ NormalWorld; String 0 #east_str; String 1 #west_str; ];|
  1334. |[ ReversedWorld; String 0 #west_str; String 1 #east_str; ];|
  1335. \endlines
  1336. where |NormalWorld| is called in |Initialise| or to go back to
  1337. normal, and |ReversedWorld| when the reflection happens.  Write
  1338. |@00| in place of |east| in any double-quoted printable string,
  1339. and similarly |@01| for |west|.  It will be printed as whichever
  1340. is currently set.  (Inform provides up to 32 such variable strings.)}
  1341.  
  1342. \section{5}{Causing actions and making new ones}
  1343.  
  1344. \widepoem
  1345. Only the actions of the just
  1346. Smell sweet and blossom in their dust.
  1347. \widepoemby{^{James Shirley} (1594-1666)}{The Contention of Ajax and Ulysses}
  1348. \quote
  1349. ...a language obsessed with action, and with the joy of seeing
  1350. action multiply from action, action marching relentlessly ahead
  1351. and with yet more actions filing in from either side to fall into
  1352. neat step at the rear, in a long straight rank of cause and
  1353. effect, to what will be inevitable, the only possible end.
  1354. \poemby{^{Donna Tartt}}{The Secret History}
  1355.  
  1356. One often wants to simulate the effect of a player typing something.
  1357. For instance, in the ^{Pepper Room} the air is full of pepper and every turn
  1358. the player sneezes and drops something at random.  If the code to do this simply
  1359. removes an object and puts it on the floor, then it might accidentally
  1360. provide a solution to a problem like ``the ^{toffee apple} sticks to your hands
  1361. so you can't drop it".
  1362.  
  1363. This can at least be coded like this:
  1364. \begindisplay
  1365. You sneeze convulsively, and lose your grip on the toffee apple...\cr
  1366. The toffee apple sticks to your hand!\cr
  1367. \enddisplay
  1368. which (though not ideal) is much better.  As an example, here is another
  1369. piece of scenery to clutter up the tiny map so far:
  1370. \beginstt
  1371. Object low_mist "low mist"
  1372.   with name "low" "swirling" "mist", article "the",
  1373.        initial "A low mist swirls about your feet.",
  1374.        description "It carries the unmistakable odour of cinnamon.",
  1375.        found_in  Square_Room  Corridor,
  1376.        before
  1377.        [; Smell: <<Examine self>>;
  1378.        ],
  1379.   has  static;
  1380. \endtt
  1381. ^^{low mist}^^|found in|
  1382. This mist is found in both the Square Room and the Corridor: note that the
  1383. |found_in| property has a list of places as its value.
  1384. \medskip
  1385.  
  1386. The player will find that smelling the mist produces the same message as
  1387. looking at it.  The command
  1388. \begintt
  1389. <<Examine self>>;
  1390. \endtt
  1391. causes the game to behave exactly as if the player had typed ``examine the
  1392. mist" at the keyboard: that is, the |Examine| action happens, applied to
  1393. the |low_mist| object.  (^|self| always means the object whose routine this
  1394. is.  In this case, it's really a bit pointless since
  1395. \begintt
  1396. <<Examine low_mist>>;
  1397. \endtt
  1398. does just the same thing.)  After going through the business of examining
  1399. the mist, the routine then returns `true', or 1 (in this case, so that the
  1400. ^{normal rules} for smelling something are stopped in their tracks).
  1401.  
  1402. If instead
  1403. \begintt
  1404. <Examine self>;
  1405. \endtt
  1406. had been used, the same would have happened, but the routine would not have
  1407. been returned from.  So the mist would be examined; and then the routine for
  1408. |Smell| would resume, and since there's nothing more to it, it would return
  1409. false; whereupon the library's usual rules would make it say something like
  1410. ``You smell nothing unusual.".
  1411.  
  1412. All ^{actions} can be written this way:
  1413. \begintt
  1414. <Look>;  <<ThrowAt cone chandelier>>;
  1415. \endtt
  1416. will, for instance, look around, then behave as if the player had asked
  1417. to throw the cone at the chandelier, then return true.
  1418. \medskip
  1419.  
  1420. \danger Internally, actions like |Look|, |ThrowAt| and |Take| are stored
  1421. as numbers, and the number associated with an action can be got at by
  1422. |x = ##Take;| for instance.  The variable |action| holds the current action number
  1423. and sometimes it's convenient to use this directly.  For instance, imagine
  1424. a mirror hung very far above the player.  Given:
  1425. \begintt
  1426. before
  1427. [; if (action==##Examine) rfalse;
  1428.    "The mirror is too high up, out of reach.";
  1429. ]
  1430. \endtt
  1431. ^^{action numbers}
  1432. the player will only be able to examine the mirror, and nothing else.
  1433. This prevents the library from ever saying something like ``You push the
  1434. mirror but nothing happens.", which would be misleading.
  1435.  
  1436. \danger
  1437. An action corresponds to a routine somewhere which actually carries out
  1438. the looking, throwing at, taking and so forth.  (Well, in fact there are
  1439. also some special actions called ``^{fake actions}" which don't correspond to
  1440. such routines, as we shall come to later.)  These have the same name as the
  1441. action with |Sub| (short for ``subroutine") on the end: so, |TakeSub| for
  1442. instance.
  1443.  
  1444. \danger
  1445. The actions implemented by the library are in three groups.  The useful ones
  1446. are in groups 2 and 3:^^{action groups}
  1447. \beginlines
  1448. |1. Quit, Restart, Restore, Verify, Save, ScriptOn, ScriptOff, Pronouns,|
  1449. |   Score, Fullscore, LMode1, LMode2, LMode3, NotifyOn, NotifyOff;|
  1450. \smallskip  
  1451. |2. Inv, InvTall, InvWide, Take, Drop, Remove, PutOn, Insert, Transfer,|
  1452. |   Empty, Enter, Exit, GetOff, Go, GoIn, Look, Examine, Give, Show,|
  1453. |   Unlock, Lock, SwitchOn, SwitchOff, Open, Close, Disrobe, Wear, Eat;|
  1454. \smallskip
  1455. |3. Yes, No, Burn, Pray, Wake, WakeOther [person],|
  1456. |   Kiss, Think, Smell, Listen, Taste, Touch, TouchThing, Dig,|
  1457. |   Cut, Jump [jump on the spot], JumpOver, Tie, Drink,|
  1458. |   Fill, Sorry, Strong [swear word], Mild [swear word], Attack, Swim,|
  1459. |   Swing [something], Blow, Rub, Set, WaveHands [ie, just "wave"],|
  1460. |   Wave [something], Pull, Push, PushDir [push something in a direction],|
  1461. |   Turn, Squeeze, LookUnder [look underneath something], Search,|
  1462. |   ThrowAt, Answer, Buy, Ask, Sing, Climb, Wait, Sleep|
  1463. \endlines{\ninepoint
  1464. Of course, the player can type all manner of things to get these.  For
  1465. instance, ``take off shirt" and ``remove the shirt" both cause the |Disrobe|
  1466. action.  Your code can ignore this complication.}
  1467.  
  1468. \ddanger Group 1 actions are called ^|meta| - they are outside the game proper,
  1469. and your code is unable to interfere with them.  (If you want a room where the
  1470. game can't be saved, as for instance ^{`Spellbreaker'} cunningly does, you'll
  1471. have to tamper with |SaveSub| directly, using a |Replace|d routine.)
  1472.  
  1473. Although all actions call the |before| routines, not all of them bother to
  1474. check |after| routines.  For instance, since the built-in |SmellSub| routine
  1475. just says ``You smell nothing out of the ordinary", there would be no point
  1476. calling |after| routines - nothing, after all, has been done.  (These are
  1477. the group 3 actions above.)
  1478.  
  1479. \danger The ones which actually do something, and call ^|after|, are:
  1480. \begintt
  1481. Inv, Take, Drop, Remove, PutOn, Insert, Exit, Go, Look, Examine, Unlock,
  1482. Lock, SwitchOn, SwitchOff, Open, Close, Disrobe, Wear, Eat, Search.
  1483. \endtt
  1484. \ddanger Some other group 2 actions use these |after| routines indirectly
  1485. - if the player empties a sack out onto the floor, this is deemed to be
  1486. a sequence of |Drop| actions, for instance, and if a sack is emptied into
  1487. a packing case this is considered a multiple insertion.
  1488.  
  1489. \ddanger ^|Search| (the searching or looking-inside-something action) is a
  1490. slightly special case between groups 2 and 3.  It never actually does anything
  1491. beyond printing messages.  What happens is that if it would be sensible to
  1492. look inside the object (i.e. if it's an open or transparent container and
  1493. there is light), |after| is called beforehand.  In this way you can use
  1494. |before| to trap searching of random scenery, and |after| to alter rules
  1495. for listing contents of containers.
  1496. \medskip
  1497.  
  1498. The library's actions are easily added to.  For instance, add the routine:
  1499. \begintt
  1500. [ BlorpleSub;
  1501.   "You speak the magic word ~Blorple~.  Nothing happens.";
  1502. ];
  1503. \endtt
  1504. (somewhere after the |Initialise| routine, say, to be tidy).  There is now
  1505. an action ^|Blorple| (though it doesn't do anything very interesting).  One
  1506. can use the command |<Blorple>;| to make it happen, and could change the
  1507. |before| routine of, say, the Corridor, to make |Blorple| do something
  1508. exciting in that one place.  In other words, |Blorple| is now an action just
  1509. like any other.^^{making actions}
  1510.  
  1511. But the player can't yet type ``blorple" and get this response, because
  1512. although the action exists, it hasn't been written into the grammar of
  1513. the game.  The grammar is a large table (mostly written out in the |Grammar|
  1514. library file).  It can easily be added to, and in this case we simply add
  1515. the lines^^{making grammar}
  1516. \begintt
  1517. Verb "blorple"
  1518.            *                                -> Blorple;
  1519. \endtt
  1520. immediately after the inclusion of the |Grammar| file.  (The spacing is
  1521. just a matter of convention.)  This is about as simple as grammar lines
  1522. come, and means that only the word ``blorple" can be used as a verb, and
  1523. it can't apply to any noun or nouns.  (Far more about grammar later.)
  1524.  
  1525.  
  1526. \danger
  1527. It is time to be more precise about the exact sequence of events.  Suppose
  1528. the player is in the ^{Bedquilt Room}, and types ``drop ^{oyster}".  Once it has
  1529. checked that this is a reasonable command, the normal rules can be
  1530. interrupted at eight different stages:\ninepoint
  1531. \item{1.} Call ^|GamePreRoutine| (if there is one).  If this returns true,
  1532. stop here.
  1533. \item{2.} Call the |before| of the player.  If this returns true, stop here.
  1534. \item{3.} Call the |before| of Bedquilt Room.  If this returns true, stop here.
  1535. \item{4.} Then the |before| of the oyster.  If this returns true, stop here.
  1536. \item{5.} Actually drop the object.
  1537. \item{6.} Call the |after| of the player. If this returns true, stop here.
  1538. \item{7.} Call the |after| of Bedquilt Room. If this returns true, stop here.
  1539. \item{8.} Then the |after| of the oyster. If this returns true, stop here.
  1540. \item{9.} Call ^|GamePostRoutine| (if there is one).  If this returns true,
  1541. stop here.
  1542. \item{10.} Print ``Dropped.''
  1543. \PAR\noindent
  1544. \ddanger
  1545. |GamePreRoutine| and |GamePostRoutine| are examples of `entry points', like
  1546. |Initialise|: routines you can provide to make global rule changes.  Their
  1547. use is a drastic measure to be avoided if possible.  The player's own
  1548. |before| and |after| will be discussed in \S 11.
  1549. \tenpoint
  1550.  
  1551. \ddanger ``Fake actions'' are just like real actions, except that they don't
  1552. occur in any game grammar, so they're never generated by the parser.  They're
  1553. a neat way to pass `messages' from one object to another one.  Because they
  1554. aren't defined implicitly in the grammar, they have to be explicitly declared
  1555. before use, by the directive:^^{passing messages}
  1556. \begindisplay
  1557. |Fake_Action| \<Action-name>\cr
  1558. \enddisplay^^|Fake Action|
  1559.  
  1560. \ddangerexercise How can you make a ^{medicine bottle}, which can be opened
  1561. in a variety of ways in the game, so that the opening-code only occurs in
  1562. the bottle definition?
  1563.  
  1564. \answer{Declare a fake action called, say, |OpenUp|.  Then:
  1565. \beginlines
  1566. |Object medicine "guaranteed child-proof medicine bottle" cupboard|
  1567. |  with name "medicine" "bottle",|
  1568. |       description "~Antidote only: no preventative effect.~",|
  1569. |       before|
  1570. |       [;  Open, Unlock: "It's adult-proof too.";|
  1571. |           Openup: give self open ~locked; "The bottle cracks open!";|
  1572. |       ],|
  1573. |  has  container openable locked;|
  1574. \endlines
  1575. Any other code in the game can execute |<OpenUp medicine>| to crack open
  1576. the bottle.}
  1577.  
  1578. \section{6}{Containers, supporters and sub-objects}
  1579.  
  1580. \quote
  1581. The concept of a surface is implemented as a special kind of containment.
  1582. Objects which have surfaces on which other objects may sit are actually
  1583. containers with an additional property of ``surfaceness".
  1584. \poemby{^{P. David Lebling}}{Zork and the Future}
  1585.  
  1586. Objects can be inside or on top of one another.  An object which has the
  1587. ^|container| attribute can contain things, like a box: one which has
  1588. ^|supporter| can hold them up, like a table.  (An object can't have both at
  1589. once.)  It can hold up to 100 items, by default: this is set by the ^|capacity|
  1590. property.
  1591.  
  1592. However, one can only put things inside a container when it has ^|open|.
  1593. If it has ^|openable|, the player can open and close it at will.  (Unless
  1594. it also has ^|locked|.)
  1595.  
  1596. To complicate matters, some containers are ^|transparent| (so that the
  1597. player can see inside them even when they are closed) and some are not.
  1598.  
  1599. \exercise Make a ^{glass box} and a ^{steel box}, which behave differently
  1600. when the lamp is shut up inside them.
  1601.  
  1602. \answer{\beginlines
  1603. |Nearby glass_box "glass box with a lid"|
  1604. |  with name "glass" "box" "with" "lid"|
  1605. |  has  container transparent openable open;|
  1606. |Nearby steel_box "steel box with a lid"|
  1607. |  with name "steel" "box" "with" "lid"|
  1608. |  has  container openable open;|
  1609. \endlines}
  1610.  
  1611. Containers (and supporters) are able to react to things being put inside
  1612. them, or removed from them, by acting on the |Receive| and |LetGo| actions.
  1613.  
  1614. \exercise Make the following, rather acquisitive bag:^^{toothed bag}
  1615. \beginstt
  1616. >put fish in bag
  1617. The bag wriggles hideously as it swallows the fish.
  1618. >get fish
  1619. The bag defiantly bites itself shut on your hand until you desist.
  1620. \endtt
  1621.  
  1622. \answer{^^{toothed bag}
  1623. \beginlines
  1624. |Object bag "toothed bag" room|
  1625. |  with name "toothed" "bag",|
  1626. |       description "A capacious bag with a toothed mouth.",|
  1627. |       before|
  1628. |       [; LetGo: "The bag defiantly bites itself \|
  1629. |                  shut on your hand until you desist.";|
  1630. |          Close: "The bag resists all attempts to close it.";|
  1631. |       ],|
  1632. |       after|
  1633. |       [; Receive:|
  1634. |                 print "The bag wriggles hideously as it swallows ";|
  1635. |                 DefArt(inp1); ".";|
  1636. |       ],|
  1637. |  has  container open;|
  1638. \endlines}
  1639.  
  1640. \danger ^|LetGo| and ^|Receive| are actually two of the ^{fake actions}:
  1641. they are the actions ^|Insert| and ^|Remove| looked at from the container's
  1642. point of view.
  1643.  
  1644. Objects which have |locked| cannot be opened, be they doors or containers
  1645. (or both).  But objects which have |lockable| can be locked or unlocked
  1646. with the appropriate key, which is declared in the |with_key| property.
  1647. (If it is undeclared, then no key will fit.)^^|with key|
  1648.  
  1649. As a final example of a container, this is a fairly typical locked
  1650. cupboard:
  1651. \beginstt
  1652. Nearby cupboard "bolted cupboard"
  1653.   with name "bolted" "cupboard",
  1654.        describe
  1655.        [; if (self hasnt open)
  1656.               "^A shut cupboard is bolted to one wall.";
  1657.           "^Bolted up on one wall is an open cupboard.";
  1658.        ],
  1659.        with_key key
  1660.   has  locked container openable lockable static;
  1661. \endtt^^{bolted cupboard}
  1662.  
  1663. Now suppose you want to make a portable television set which has four
  1664. different buttons on it.  Obviously when the television moves, its buttons
  1665. should move with it, and the sensible way to arrange this is to make the
  1666. four buttons possessions of the |television| object.
  1667.  
  1668. However, the television isn't a |container|, and the player can't normally
  1669. ``see'' (that is, refer to) the possessions of an
  1670. object.  So how do we bring the buttons into the player's ``view'' without
  1671. making them removable, or allowing anyone to put extra things ``into''
  1672. the television?
  1673.  
  1674. This is what the ^|transparent| attribute is for: it is an extremely useful
  1675. device to allow the player to ``see'' (i.e. talk about) the contents of
  1676. an object.
  1677.  
  1678. \exercise Implement a ^{television set} with attached power button and
  1679. screen.
  1680.  
  1681. \answer{\beginlines^^{television set}
  1682. |Object television "portable television set" lounge|
  1683. |  with name "tv" "television" "set" "portable",|
  1684. |       before|
  1685. |       [;  SwitchOn: <<SwitchOn power_button>>;|
  1686. |           SwitchOff: <<SwitchOff power_button>>;|
  1687. |           Examine: <<Examine screen>>;|
  1688. |       ],|
  1689. |  has  transparent;|
  1690. |Nearby power_button "power button"|
  1691. |  with name "power" "button" "switch",|
  1692. |       after|
  1693. |       [;  SwitchOn, SwitchOff: <<Examine screen>>;|
  1694. |       ],|
  1695. |  has  switchable;|
  1696. |Nearby screen "television screen"|
  1697. |  with name "screen",|
  1698. |       before|
  1699. |       [;  Examine: if (power_button hasnt on) "The screen is black.";|
  1700. |               "The screen writhes with a strange Japanese cartoon.";|
  1701. |       ];|
  1702. \endlines}
  1703.  
  1704. \section{7}{Doors}
  1705.  
  1706. \quote
  1707. Standing in front of you to the north, however, is a door surpassing
  1708. anything you could have imagined. For starters, its massive lock is
  1709. wrapped in a dozen six-inch thick iron chains. In addition, a certain
  1710. five-headed monster...
  1711. \poemby{^{Marc Blank} and ^{P. David Lebling}}{^{`Enchanter'}}
  1712. \widepoem
  1713. O for doors to be open and an invite with gilded edges
  1714. To dine with Lord Lobcock and Count Asthma.
  1715. \poemby{^{W. H. Auden} (1907-1973)}{Song}
  1716.  
  1717. A useful kind of object is a ^|door|.  This need not literally be a door:
  1718. it might be a rope-bridge or a ladder, for instance.  To set up a |door|:
  1719. \item{(a)} give the object the |door| attribute;
  1720. \item{(b)} set the |door_to| property to the destination;
  1721. \item{(c)} set the |door_dir| property to the direction which that would be,
  1722. such as |n_to|;
  1723. \item{(d)} make the room's ^{map} connection in that direction point to the
  1724. door itself.
  1725. ^^|door to|^^|door dir|
  1726. \PAR\noindent For example, here is a closed and locked door:^^{rusty door}
  1727. \beginlines
  1728. |Object In_Immense_N_S_Passage "Immense N/S Passage"|
  1729. |  with description "One end of an immense north/south passage.",|
  1730. |       s_to In_Giant_Room,|
  1731. |       n_to RustyDoor;|
  1732. |Nearby RustyDoor "rusty door"|
  1733. |  with description "It's just a big iron door.",|
  1734. |       name "door" "hinge" "hinges" "massive" "rusty" "iron",|
  1735. |       when_closed|
  1736. |           "The way north is barred by a massive, rusty, iron door.",|
  1737. |       when_open|
  1738. |           "The way north leads through a massive, rusty, iron door.",|
  1739. |       door_to In_Cavern_With_Waterfall,|
  1740. |       door_dir n_to,|
  1741. |       with_key set_of_keys|
  1742. |  has  static door openable lockable locked;|
  1743. \endlines
  1744. (Note that the door is ^|static| - otherwise the player could pick it up and
  1745. walk away with it!)  The properties |when_closed| and |when_open| give
  1746. descriptions appropriate for the door in these two states.
  1747. ^^|when closed|^^|when open|
  1748.  
  1749. Doors are rather one-way: they are only really present on one side.  If
  1750. a door needs to be accessible (openable and lockable from either side),
  1751. a neat trick is to make it present in both locations and to fix the
  1752. |door_to| and |door_dir| to the right way round for whichever side the player
  1753. is on.  Here, then, is a ^{two-way door}:^^{steel grate}
  1754. \beginlines
  1755. |Object Grate "steel grate"|
  1756. |  with name "grate" "lock" "gate" "grille" "metal"|
  1757. |            "strong" "steel" "grating",|
  1758. |       description "It just looks like an ordinary grate \|
  1759. |           mounted in concrete.",|
  1760. |       with_key set_of_keys,|
  1761. |       door_dir|
  1762. |       [; if (location==Below_The_Grate) return u_to; return d_to; ],|
  1763. |       door_to|
  1764. |       [; if (location==Below_The_Grate) return Outside_Grate;|
  1765. |          return Below_The_Grate; ],|
  1766. |       describe|
  1767. |       [; if (self has open) "^The grate stands open.";|
  1768. |          if (self hasnt locked) "^The grate is unlocked but shut.";|
  1769. |          rtrue; ],|
  1770. |       found_in  Below_The_Grate  Outside_Grate|
  1771. |  has  static door openable lockable locked;|
  1772. \endlines
  1773. where |Below_The_Grate| has |u_to| set to |Grate|, and |Outside_Grate| has
  1774. |d_to| set to |Grate|.  The grate can now be opened, closed, entered and
  1775. locked from either above or below.
  1776.  
  1777. \danger  At first sight, it isn't obvious why doors have the |door_dir|
  1778. ^^|door dir|
  1779. property.  Why does a door need to know which way it faces?  The idea is
  1780. that if there's an open door in the south wall, a player can go through it
  1781. either by typing ``south'' or ``enter door".  So what the |Enter| action
  1782. does (provided the door is actually open) is to cause the |Go| action with
  1783. the given direction.
  1784.  
  1785. \danger This has one practical consequence: if you put |before| and |after|
  1786. routines on the ^|Enter| action for the |Grate|, they only apply to a player
  1787. typing ``enter grate" and not to one just typing ``down".  The way to trap
  1788. both at once is to write a routine for the |d_to| property of |Outside_Grate|.
  1789.  
  1790.  
  1791. \section{8}{Switchable objects}
  1792.  
  1793. \quote
  1794. In one corner there is a machine which is reminiscent of a clothes dryer.
  1795. On its face is a switch which is labelled ``START". The switch does not
  1796. appear to be manipulable by any human hand (unless the fingers are about
  1797. 1/16 by 1/4 inch)...
  1798. \quoteby{{\sl Zork}}
  1799.  
  1800. Objects can also be ^|switchable|.  This means they can be turned off or
  1801. on, as if they had some kind of switch on them.  The object has the
  1802. attribute ^|on| if it's on.  For example:^^{searchlight}
  1803. \beginlines
  1804. |Object searchlight "Gotham City searchlight" skyscraper|
  1805. |  with name "search" "light" "template", article "the",|
  1806. |       description "It has some kind of template on it.",|
  1807. |       when_on "The old city searchlight shines out a bat against \|
  1808. |                the feather-clouds of the darkening sky.",|
  1809. |       when_off "The old city searchlight, neglected but still \|
  1810. |                 functional, sits here."|
  1811. |  has  switchable static;|
  1812. \endlines
  1813. Here is a lamp which provides for ^{batteries} which will some day run down,
  1814. though the code to actually deplete these batteries (by decrementing |time_left|
  1815. every turn it's switched on) is omitted:^^{brass lantern}
  1816. \beginlines
  1817. |Nearby brass_lantern "brass lantern"|
  1818. |  with name "lamp" "lantern" "shiny" "brass",|
  1819. |       when_off  "There is a shiny brass lamp nearby.",|
  1820. |       when_on   "Your lamp is here, gleaming brightly.",|
  1821. |       time_left 330,|
  1822. |       before|
  1823. |       [; Examine: print "It is a shiny brass lamp";|
  1824. |                if (brass_lantern hasnt on)|
  1825. |                    ".  It is not currently lit.";|
  1826. |                if (brass_lantern.time_left < 30)|
  1827. |                    ", glowing dimly.";|
  1828. |                ", glowing brightly.";|
  1829. |          Burn: <<SwitchOn brass_lantern>>;|
  1830. |          Rub:  "Rubbing the electric lamp is not particularly \|
  1831. |                 rewarding.  Anyway, nothing exciting happens.";|
  1832. |          SwitchOn: if (brass_lantern.time_left <= 0)|
  1833. |                "Unfortunately, the batteries seem to be dead.";|
  1834. |       ],|
  1835. |       after|
  1836. |       [; SwitchOn: give brass_lantern light;|
  1837. |          SwitchOff: give brass_lantern ~light;|
  1838. |       ],|
  1839. |  has  switchable;|
  1840. \endlines
  1841.  
  1842. \section{9}{Things to enter, travel in and push around}
  1843.  
  1844. \quote
  1845. ...the need to navigate a newly added river prompted the invention
  1846. of vehicles (specifically, a boat).
  1847. \quoteby{^{P. David Lebling}, ^{Marc Blank} and ^{Timothy Anderson}}
  1848.  
  1849. Some objects in a game are ^|enterable|, which means that a player can
  1850. get inside them.  The idea of ``inside" here is that the player is only
  1851. half-in, as with a car or a psychiatrist's couch.  (If it's more like a
  1852. prison cell, then it should be a separate place.)  In practice one often
  1853. wants to make an |enterable| thing also a |container|, or, as in this
  1854. example, a ^|supporter|:
  1855. \beginstt
  1856. Object chair "dentist's chair" surgery
  1857.   with name "dentists" "chair" "couch",
  1858.   has  enterable supporter;
  1859. \endtt^^{dentist's chair}
  1860. \medskip
  1861.  
  1862. All the classic games have ^{vehicles} (like boats, or fork lift trucks, or
  1863. hot air balloons) which the player can journey in, so Inform makes this
  1864. easy.  Here is a simple case:
  1865. \beginlines
  1866. |Object car "little red car" cave|
  1867. |  with name "little" "red" "car",|
  1868. |       longdesc "Large enough to sit inside.  Among the controls is a \|
  1869. |                 prominent on/off switch.  The numberplate is KAR 1.",|
  1870. |       initpos "The red car sits here, its engine still running.",|
  1871. |       closedpos "A little red car is parked here.",|
  1872. |       before|
  1873. |       [; Go: if (car has on) "Brmm!  Brmm!";|
  1874. |              print "(The ignition is off at the moment.)^";|
  1875. |       ],|
  1876. |  has  switchable enterable static container open;|
  1877. \endlines^^{little red car}^^{The Prisoner}
  1878. Actually, this demonstrates a special rule.  If a player is inside an
  1879. |enterable| object and tries to move, say ``north", the |before| routine
  1880. for the object is called with the action ^|Go|, and |n_obj| as the noun.
  1881. If it returns false, the game disallows the attempt to move (as usual).
  1882. If it returns true, then the vehicle and player move together via the
  1883. game's usual map.
  1884.  
  1885. \danger Because you might want to drive the car ``out'' of a garage,
  1886. the ^{``out'' verb} does not make the player get out of the car.  Usually
  1887. the player has to type something like ``get out'' to make this happen,
  1888. though of course the rules can be changed.
  1889.  
  1890. \exercise Alter the car so that it won't go up or down stairs.
  1891.  
  1892. \answer{Change the car's |before| to\beginlines
  1893. |    before|
  1894. |    [; Go: if (noun==d_obj or u_obj)|
  1895. |           {   print "(The car will never get over those stairs.)^";|
  1896. |               rfalse;|
  1897. |           }|
  1898. |           if (car has on) "Brmm!  Brmm!";|
  1899. |           print "(The ignition is off at the moment.)^";|
  1900. |    ],|
  1901. \endlines^^{little red car}}
  1902.  
  1903. \danger
  1904. Objects like the car (if the hand brake is off) or, say, an antiquated
  1905. wireless on casters, are obviously too heavy to pick up but the player
  1906. should at least be able to push them from place to place.  When the
  1907. player tries to do this, the ^|PushDir| action is generated.  Now, if
  1908. the |before| routine returns false, the game will just say that the
  1909. player can't; and if it returns true, the game will do nothing at all,
  1910. guessing that the |before| routine has already printed something more
  1911. interesting.  So how does one actually tell Inform that the push
  1912. should be allowed?  The answer is that one has to do two things:
  1913. call the ^|AllowPushDir()| routine (a library routine), and then
  1914. return true.  So, for example,
  1915. \beginlines
  1916. |Nearby huge_ball "huge plaster-of-paris ball"|
  1917. |  with name "huge" "plaster" "ball",|
  1918. |       description "A good eight feet across, though fairly lightweight.",|
  1919. |       initial|
  1920. |           "A huge plaster-of-paris ball rests here, eight feet wide.",|
  1921. |       before|
  1922. |       [; PushDir: AllowPushDir(); rtrue;|
  1923. |          Take, Remove: "There's a lot of plaster in an eight-foot sphere.";|
  1924. |       ],|
  1925. |       after|
  1926. |       [; PushDir:|
  1927. |              "The ball rattles about and is hard to stop once underway.";|
  1928. |       ],|
  1929. |  has  static;|
  1930. \endlines^^{plaster of paris}
  1931.  
  1932.  
  1933. \section{10}{Living creatures and conversation}
  1934.  
  1935. \widepoem
  1936. To know how to live is my trade and my art.
  1937. \poemby{^{Michel de Montaigne} (1533-1592)}{Essays}
  1938.  
  1939. \widepoem
  1940. Everything that can be said can be said clearly.
  1941. \poemby{^{Ludwig Wittgenstein} (1889-1951)}{Tractatus}
  1942.  
  1943. This rummage through special kinds of objects finishes up with the most
  1944. sophisticated kind: living ones.
  1945. Animate objects (such as sea monsters, mad aunts or nasty little dwarves)
  1946. have a property called ^|life|, containing their rules.  This behaves just
  1947. like a |before| or |after| routine, but only the following actions apply:
  1948. \medskip
  1949. \noindent ^|Attack|
  1950. \qquad The player is making hostile advances...
  1951. \medskip
  1952. \noindent ^|Kiss|
  1953. \qquad ...or excessively friendly ones.
  1954. \medskip
  1955. \noindent ^|ThrowAt|
  1956. \qquad The player asked to throw |noun| at the creature.
  1957. \medskip
  1958. \noindent ^|Give|
  1959. \qquad The player asked to give |noun| to the creature...
  1960. \medskip
  1961. \noindent ^|Show|
  1962. \qquad ...or just to show it.
  1963. \medskip
  1964. \noindent ^|Ask|
  1965. \qquad The player asked the creature about something: |noun| holds the
  1966. word.
  1967. \medskip
  1968. \noindent ^|Answer|
  1969. \qquad The player tried either of:
  1970. \begindisplay
  1971. ``answer \<word> to troll"\cr
  1972. ``troll, \<something not understood>"\cr
  1973. \enddisplay
  1974. In either case the variable
  1975. |special_word|
  1976. ^^|special word|
  1977. is set to the dictionary entry of the first word, or
  1978. 0 if it isn't in the dictionary, and |special_number|
  1979. ^^|special number|
  1980. is set to an attempt to read it as a number.  (For instance,
  1981. ``computer, 143" will cause |special_number| to be set to 143.)
  1982. \medskip
  1983. \noindent ^|Order|
  1984. \qquad On the other hand, an |Order| happens when the parser does understand
  1985. what the player wants the creature to do: e.g., ``troll, go south".
  1986. |action|, |noun| and |second| are set up
  1987. as usual: in this case |action=##Go| and |noun=s_obj|, while |second=0|.
  1988. \bigskip
  1989.  
  1990. If the routine doesn't exist, or returns false, events will take their
  1991. usual course.  Here is a full example:
  1992. \beginstt
  1993. Object snake "sullen snake" mists
  1994.   with name "sullen" "snake",
  1995.        description "Perhaps a boa constrictor.  Perhaps not.",
  1996.        life
  1997.        [; Order:   if (action==##Go)
  1998.                        "The snake wasn't born yesterday.";
  1999.           Attack:  "Lazily, the snake dodges your attack.";
  2000.           Kiss:    "What a repulsive idea.";
  2001.           ThrowAt: print "Effortlessly, the snake dodges ";
  2002.                    DefArt(inp1); ".";
  2003.           Answer, Show:  "The snake disdains to comment.";
  2004.           Ask:     if (noun == 'mists')
  2005.                        "~Healthy and good for the skin, mists.~";
  2006.                    "~I'm only the obligatory monster.~";
  2007.           Give:    if (noun has edible)
  2008.                    {   remove noun;
  2009.                        "~Mmm!  Thanks!  I still hate you, though.~";
  2010.                    }
  2011.                    "~Bleurghh!  Are you trying to poison me?~";
  2012.        ],
  2013.   has  animate;
  2014. \endtt^^{sullen snake}
  2015. Of course an |animate| still has |before| and |after| routines like any
  2016. other, so you can trap many other kinds of behaviour.  (The library
  2017. understands that, for example, an |animate| creature cannot be taken.)
  2018.  
  2019. \danger |DefArt| is a routine which prints the short name of an object
  2020. along with its definite article, usually ``the".
  2021.  
  2022. Sometimes creatures should be ^|transparent|, sometimes not.  Consider these
  2023. two cases of |animate| characters, for instance:
  2024. \item{$\bullet$} an urchin with something bulging inside his jacket pocket;
  2025. \item{$\bullet$} a hacker who has a bunch of keys hanging off his belt.
  2026.  
  2027. \noindent
  2028. The hacker is |transparent|, the urchin not.  That way the parser prevents
  2029. the player from referring to whatever the urchin is hiding (even if the
  2030. player has played the game before, and knows what is in there and what it's
  2031. called).  But the player can look at and be tantalised by the hacker's
  2032. keys.^^{hacker and urchin}^^{urchin and hacker}
  2033.  
  2034. \danger Another way to trap some of these actions (those which do not
  2035. involve conversation, i.e. other than |Order|, |Answer| or |Ask|) is to
  2036. use |before| in the ordinary way.  This lets you change rules about, say,
  2037. giving things to people in particular places.  The ^|ThrowAt| action is
  2038. also an ordinary one (for coconut shies, greenhouse windows and the like)
  2039. but is given to |life| as well because most creatures react to it, and
  2040. it's a convenience to have all the rules for a creature in one place.
  2041.  
  2042. \danger A footnote about |Order|: this is another ``fake action".
  2043. ^^{fake actions}
  2044. The |before| and |after| routines of a room can't detect the player having
  2045. given a request to another character.  Also, if you want the snake to
  2046. obey when the player tells it to take something, you have to write the code
  2047. to do the actual taking yourself.  This isn't any problem in practice.  (Try
  2048. looking at the code for |Christopher| in the ``Toyshop" example game.)
  2049.  
  2050.  
  2051. \section{11}{Starting, moving, changing and killing the player}
  2052.  
  2053. \quote
  2054. There are only three events in a man's life; birth, life and death;
  2055. he is not conscious of being born, he dies in pain and he forgets
  2056. to live.
  2057. \quoteby{^{Jean de la Bruy\`ere} (1645-1696)}
  2058. \quote
  2059. That is the road we all have to take - over
  2060. the Bridge of Sighs into eternity.
  2061. \quoteby{^{S\o ren Kierkegaard} (1813-1855)}
  2062. ^^{depressed philosophers}
  2063.  
  2064. The player normally begins in the room which |location| is set to, and
  2065. setting |location| is the only absolute obligation on a game's ^|Initialise|
  2066. routine.  (The room may be initially dark if you so choose, or rather
  2067. if you provide no light source.)  In fact |location| could be set to a
  2068. ^{chair} or bed just as easily if the player is to start seated or lying
  2069. down.
  2070. If you would like to give the player some items to begin with, ^|Initialise|
  2071. should also |move| them to |player|.^^{player's origin}^^{initial possessions}
  2072. \medskip
  2073.  
  2074. To move the player about (for ^{teleportation} of some kind), two things
  2075. must be done: to move the player object, by^^{moving the player}
  2076. \beginstt
  2077. move player to newroom;
  2078. \endtt
  2079. and also to change the ^|location| variable, which says which room to
  2080. display on the status line:
  2081. \beginstt
  2082. location = newroom;
  2083. \endtt
  2084. The cleanest way to move the player is call |PlayerTo(place);| which also
  2085. sorts out things like only printing the new room's description if there's
  2086. enough light there to see by.^^|PlayerTo|
  2087.  
  2088. \danger
  2089. In general |location| can be different from |parent(player)| in two ways:
  2090. it can be ``Darkness" (that is, the special object ^|thedark|, which behaves
  2091. somewhat like a room), or it can be the actual room while |parent(player)|
  2092. is something the player sits inside, like (say) a jeep.
  2093.  
  2094. \danger Calling |PlayerTo(place, 1);| will move the player without printing
  2095. anything, and in particular without printing any room description.
  2096. \medskip
  2097.  
  2098. The player's whole persona can easily be changed, by setting
  2099. \beginstt
  2100. player.before = #r$MyNewRule;
  2101. \endtt^^{changing the player}
  2102. where |MyNewRule| is a new |before| rule to be applied to every action of
  2103. the player's (or similarly for an |after| rule).  For instance, if a cannon
  2104. goes right next to the player, a period of deafness might ensue, and this
  2105. rule could stop the |Listen| action from taking its normal course.
  2106.  
  2107. \danger In fact a much more powerful trick is available: the |player| can
  2108. actually become a different character in the game, allowing the real player
  2109. at the keyboard to act through someone else.
  2110. Calling |ChangePlayer(obj)| will transform the player to |obj|.  There's
  2111. no need for |obj| to have names like ^{``me''} or ^{``myself''}; the
  2112. parser understands these words automatically to refer to the
  2113. currently-inhabited |player| object.  However, it must provide a |number|
  2114. property (which the library will use for workspace).  The maximum number
  2115. of items the player can carry as that object will be its ^|capacity|.  Finally,
  2116. since |ChangePlayer| prints nothing, you may want to conclude with a |<<Look>>;|
  2117.  
  2118. \ninepoint ^|ChangePlayer| has many possible applications.  The player
  2119. who tampers with Dr ^{Frankenstein}'s ^{brain transference machine} may
  2120. suddenly become the Monster strapped to the table.  A player who drinks
  2121. too much wine could become a ^{`drunk player object'} to whom many different
  2122. rules apply.  The ^{``snavig'' spell} of ^{`Spellbreaker'}, which transforms
  2123. the player to an animal like the one cast upon, could be implemented thus.
  2124. More ambitiously, a game could have a stock of half a dozen main characters,
  2125. and the focus of play can switch between them.  A player might have a ^{team
  2126. of four adventurers} to explore a dungeon, and be able to switch the one
  2127. being controlled by typing the name.  (In this case, an |AfterLife| routine
  2128. -- see below -- may be needed to switch the focus back to a still-living
  2129. member of the team after one has met a sticky end.)^^{`focus' of game}
  2130. \tenpoint
  2131.  
  2132. \dangerexercise In Central American legend, a sorceror can transform himself
  2133. into a {\it ^{nagual}}, a familiar such as a spider-monkey; indeed, each
  2134. individual has an animal self or {\it wayhel}, living in a volcanic land
  2135. over which the king, as a jaguar, rules.  Turn the player into his
  2136. {\it wayhel}.
  2137.  
  2138. \answer{The common man's {\it wayhel} was a lowly mouse.  Since we think
  2139. much more highly of the player:
  2140. \beginlines
  2141. |Object hog "Warthog" Caldera|
  2142. |  with name "wart" "hog" "warthog", description "Muddy and grunting.",|
  2143. |       number 0,|
  2144. |       initial "A warthog snuffles and grunts about in the ash.",|
  2145. |       before|
  2146. |       [; if (player==self && action~=##Go or ##Look or ##Examine)|
  2147. |              "Warthogs can't do anything as tricky as that!";|
  2148. |       ],|
  2149. |  has  animate proper;|
  2150. \endlines^^{warthog}^^{nagual}
  2151. and we just |ChangePlayer(warthog);|.  Note that this |before| rule is
  2152. carefully written only to affect actions of the player-as-warthog.
  2153. If the player-as-human should find and try to ``take warthog'', this
  2154. |before| routine won't interfere.}
  2155.  
  2156. \danger Calling |ChangePlayer(object,1);| will do the same but make the
  2157. game print ``(as Whoever)'' during room descriptions.
  2158.  
  2159. \medskip
  2160. The player is still alive for as long as the variable |deadflag| is zero.
  2161. When set to 1, the player dies; when set to 2, the player wins; and all higher
  2162. values are taken as more ^{exotic forms of death}.  Now Inform does not know
  2163. what to call these exotica: so if they should arise, it calls the
  2164. ^|DeathMessage| routine, which is expected to look at ^|deadflag| and
  2165. can then print something like ``You have changed''.
  2166.  
  2167. Many games allow reincarnation (or, as ^{David M. Baggett} points out, in
  2168. fact ^{resurrection}).  You too can allow this, by providing an ^|AfterLife|.
  2169. This routine gets the chance to do as it pleases before any ``You are
  2170. dead'' type message appears, including resetting |deadflag| back to 0 -
  2171. which causes the game to proceed in the normal way, rather than end.
  2172. |AfterLife| routines can be tricky to write, though, because the game
  2173. has to be set to a state which convincingly reflects what has happened.
  2174. (For instance, try collapsing the bridge in ^{`Advent'} by leading the
  2175. bear across it, then being reincarnated and returning to the scene.)
  2176.  
  2177.  
  2178. \section{12}{Printing out names of objects}
  2179.  
  2180. \poem
  2181. And we were angry and poor and happy,
  2182. And proud of seeing our names in print.
  2183. \poemby{^{G. K. Chesterton} (1874-1936)}{A Song of Defeat}
  2184.  
  2185. Inform has a special form of print command for this, ^|print object|, but
  2186. {\it do not use it}.  Instead, call one of the following library routines:
  2187. \smallskip{
  2188. \settabs 8 \columns
  2189. \+ &^|DefArt(obj)|         &&& Print the object with its definite article\cr
  2190. \+ &^|CDefArt(obj)|        &&& The same, but capitalised\cr
  2191. \+ &^|InDefArt(obj)|       &&& Print the object with indefinite article\cr
  2192. \+ &^|PrintShortName(obj)| &&& Print the object's short name alone\cr
  2193. }
  2194. \medskip
  2195.  
  2196. The ^{indefinite article} for an object is held in the property ^|article|
  2197. and is assumed to be `a' if none is declared.  That means that if the
  2198. short name starts with a vowel, you need to set it to `an'.  But |article|
  2199. offers much more amusement:
  2200. \begindisplay
  2201. a platinum bar, an orange balloon, your Aunt Jemima,\cr
  2202. some bundles of reeds, far too many marbles\cr
  2203. \enddisplay
  2204. are all examples of |article|s.
  2205.  
  2206. Definite articles are always ``the'' unless an object is given the
  2207. attribute |proper|, which makes it a ^{proper noun} and so not take a
  2208. ^{definite article} at all.  Thus
  2209. \begindisplay
  2210. the platinum bar, Aunt Jemima, Elbereth\cr
  2211. \enddisplay
  2212. are all printed by |DefArt|, the latter two being ^|proper|.
  2213.  
  2214. As we shall later see, changing the short name is easy.
  2215.  
  2216. \dangerexercise Why does
  2217. \begintt
  2218. print CDefArt(obj), " falls to the floor.^";
  2219. \endtt
  2220. seem to work, but mysteriously print the number 1 after the name of the
  2221. object?
  2222.  
  2223. \answer{Because |CDefArt(obj)| is a function call which, as it happens,
  2224. returns the value true, or 1 (not that this signifies anything), and
  2225. |print| thinks it is printing out a number.}
  2226.  
  2227. \ddanger The reason |print object| is unsafe is that it prints the real,
  2228. ``hardware and unchangeable'' short name, whereas we want everything to
  2229. work nicely when the user changes the short name of an object in play:
  2230. so the library routines almost all indirect through |PrintShortName|
  2231. (except in two cases to do with |ChangePlayer|, since the current
  2232. player's short name is always ``yourself'').
  2233.  
  2234. \section{13}{Classes of objects}
  2235.  
  2236. In most games there are groups of objects with certain rules in common.
  2237. As well as individual objects, Inform allows one to define
  2238. ^{classes} in almost exactly the same way.  The only
  2239. difference between the layout of a class and object definition is that
  2240. a class has no short name or initial location (since it does not correspond
  2241. to a single real item).  For example:
  2242. \beginlines
  2243. | Class Treasure|
  2244. |  with depositpoints 10,|
  2245. |       after|
  2246. |       [; Take: if (location==Inside_Building)|
  2247. |                     score=score-self.depositpoints;|
  2248. |                score=score+5;|
  2249. |                "Taken!";|
  2250. |          Drop: score=score-5;|
  2251. |                if (location==Inside_Building)|
  2252. |                {   score=score+self.depositpoints;|
  2253. |                    "Safely deposited.";|
  2254. |                }               |
  2255. |       ],|
  2256. |  has  valuable;|
  2257. \endlines^^{treasure class}
  2258. An object of this class inherits the properties and attributes it defines:
  2259. in this case, an object of class |Treasure| picks up the given score and
  2260. rules automatically.  So
  2261. \beginstt
  2262. Nearby bars_of_silver "bars of silver"
  2263.  class Treasure
  2264.   with description "They're probably worth a fortune!",
  2265.        initial "There are bars of silver here!",
  2266.        article "some",
  2267.        name "silver" "bars";
  2268. \endtt^^{silver bars}
  2269. inherits the |depositpoints| value of 10 and the rules about taking
  2270. and dropping.  If the silver bars had themselves set |depositpoints|
  2271. to 15, say, then the value would be 15: i.e., the class would be
  2272. over-ridden.
  2273.  
  2274. \danger |depositpoints| isn't a library property: it's one defined in the
  2275. game this example is drawn from, the ^{`Advent'} example game.
  2276.  
  2277. We could also, for instance, have:
  2278. \beginlines
  2279. |Nearby cake "valuable cake"|
  2280. | class Treasure|
  2281. |  with description "Exquisite!",|
  2282. |       initial "There's a valuable cake here!",|
  2283. |       after|
  2284. |       [; Eat: "Your most expensive meal in ages, but worth it.";|
  2285. |       ],|
  2286. |       name "valuable" "cake"|
  2287. |  has  edible;|
  2288. \endlines^^{valuable cake}
  2289. Now the cake has two |after| rules.  Both apply, but the rule in the cake
  2290. itself takes ^{precedence}, i.e., happens first.
  2291.  
  2292. \danger 
  2293. An object can inherit from several classes at once.  Moreover, a class can
  2294. itself inherit from other classes, so one can easily make a class for
  2295. ``like Treasure but with only 8 |depositpoints|''.
  2296.  
  2297. \ddanger
  2298. The ^|class| field of an object definition contains a list of classes,
  2299. \begindisplay
  2300. |class| $C_1$ ... $C_n$
  2301. \enddisplay^^{inheritance}
  2302. in which case the object inherits first from $C_1$, then from $C_2$
  2303. and so on.  $C_2$ over-rides $C_1$ and so on along the line.  These
  2304. classes may well disagree with each other, so the order matters.  If $C_1$
  2305. says |depositpoints| is 5, $C_3$ says it is 10 but the object
  2306. definition itself says 15 then the answer is 15.
  2307.  
  2308. \ddanger
  2309. With some properties, the value is not replaced but added to: this
  2310. is what happened with |after| above.  These
  2311. properties are those which were declared as ^|additive|, e.g. by
  2312. \begintt
  2313. Property additive before $ffff;
  2314. \endtt
  2315. For instance, the standard Inform properties |name| and |before| are
  2316. both additive.  So we could add |name "treasure",| to the properties
  2317. in the class definition for |Treasure|, and then all objects of that
  2318. class would respond to the word ``treasure'', as well as their own
  2319. particular names.
  2320.  
  2321.  
  2322. \section{14}{Daemons and the passing of time}
  2323.  
  2324. \quote
  2325. Some, such as Sleep and Love, were never human.  From this
  2326. class an individual daemon is allotted to each human being
  2327. as his `witness and guardian' through life.
  2328. \poemby{^{C. S. Lewis} (1898-1963)}{The Discarded Image}
  2329. \widepoem
  2330. Some daemon stole my pen (forgive th' offence)
  2331. And once betrayed me into common sense.
  2332. \poemby{Alexander Pope (1688-1744)}{The Dunciad}
  2333.  
  2334. By tradition, a daemon is an event which happens each turn while it
  2335. is `active'.  The classic example is of a dwarf which appears in the
  2336. cave: it has a daemon routine attached for moving about, throwing
  2337. knives at the player and other pleasantries.^^{daemons}
  2338.  
  2339. Each object can have a ^|daemon| of its own.  This is set going, and stopped
  2340. again, by calling the (library) routines
  2341. \begintt
  2342. StartDaemon(the-object);
  2343. StopDaemon(the-object);
  2344. \endtt
  2345. Once active, the |daemon| property of the object is called as a routine
  2346. each turn.  Daemons are often started by a game's |Initialise| routine,
  2347. and active throughout.^^|StartDaemon|^^|StopDaemon|
  2348.  
  2349. \danger Be warned: this continues to happen even if the daemon is
  2350. associated with a room or item which has been left behind by the player.
  2351. Actually this is very useful, as it means daemons can be used for
  2352. `^{tidying-up operations}', or for the consequences of the player's actions
  2353. to catch up with him.
  2354.  
  2355. Daemons often run a fair amount of code.  (There are plenty of good
  2356. examples in ^{`Toyshop'} and ^{`Advent'}.)  They shouldn't be ridiculously
  2357. slow if they will run more than once.  And some daemons so sit in
  2358. the background for enormously long times: for instance, the daemon in
  2359. ``Advent'' which hides until the player has managed to get all the
  2360. treasures, then pounces.  Such daemons ought to
  2361. check their condition and return as quickly as possible if it fails.
  2362.  
  2363. \exercise  Many games contain ^{`wandering monsters'}, characters who walk
  2364. around the map (usually hand-coded and not moving far abroad).  Use a daemon
  2365. to implement one who wanders as freely as the player, like the
  2366. ^{thief in `Zork I'}^^{`Zork I'}.
  2367.  
  2368. \answer{This is a crude implementation, for brevity (the real Zork I
  2369. thief has an enormous stock of attached messages).^^{thief in `Zork I'}
  2370. \beginlines
  2371. |Object thief "thief" Danger_Zone|
  2372. |  with name "thief",|
  2373. |       each_turn "^The thief growls menacingly.",|
  2374. |       daemon|
  2375. |       [ i p j n k;|
  2376. |           if (random(3)~=1) rfalse;|
  2377. |           p=parent(thief);|
  2378. |           objectloop (i in compass)|
  2379. |           {   j=p.(i.door_dir);|
  2380. |               if (j>player && j<=top_object && j hasnt door) n++;|
  2381. |           }|
  2382. |           if (n==0) rfalse;|
  2383. |           k=random(n); n=0;|
  2384. |           objectloop (i in compass)|
  2385. |           {   j=p.(i.door_dir);|
  2386. |               if (j>player && j<=top_object && j hasnt door) n++;|
  2387. |               if (n==k)|
  2388. |               {   move self to j;|
  2389. |                   if (p==location) "^The thief stalks away!";|
  2390. |                   if (j==location) "^The thief stalks in!";|
  2391. |                   rfalse;|
  2392. |               }|
  2393. |           }|
  2394. |       ];|
  2395. \endlines
  2396. This thief walks at random and cannot pass through doors, bridges and the like
  2397. (because these may be locked or have rules attached); it's only a first
  2398. approximation, and in a good game one should occasionally see the thief do
  2399. something surprising, such as open a secret door.}
  2400.  
  2401. \exercise
  2402. Use a ^{background daemon} to implement a system of ^{weights}, so
  2403. that the player can only carry a certain weight before her strength gives
  2404. out and she is obliged to drop something.  It should allow for feathers to
  2405. be lighter than lawn-mowers.
  2406.  
  2407. \answer{First define a new property for object weight:^^{weights}
  2408. \beginlines
  2409. |Property weight 10;|
  2410. \endlines
  2411. (10 being an average sort of weight).  Containers weigh more when
  2412. they hold things, so we will need:
  2413. \beginlines
  2414. |[ WeightOf obj t i;|
  2415. |   t = obj.weight;|
  2416. |   objectloop (i in obj) t=t+WeightOf(i);|
  2417. |   return t;|
  2418. |];|
  2419. \endlines
  2420. Now for the daemon which monitors the player's fatigue:^^{fatigue daemon}
  2421. \beginlines
  2422. |Object weigher "weigher"|
  2423. |  with number 500,|
  2424. |       time_left 5,|
  2425. |       daemon|
  2426. |       [ w s b bw;|
  2427. |            w=WeightOf(player)-100-player.weight;|
  2428. |            s=self.number; s=s-w; if (s<0) s=0; if (s>500) s=500;|
  2429. |            self.number = s;|
  2430. |            if (s==0)|
  2431. |            {   bw=-1;|
  2432. |                objectloop(b in player)|
  2433. |                    if (WeightOf(b)>bw) { bw=WeightOf(b); w=b; }|
  2434. |                print "^Exhausted with carrying so much, you decide \|
  2435. |                    to discard "; DefArt(w); print ": "; <<Drop w>>;|
  2436. |            }|
  2437. |            w=s/100; if (w==self.time_left) rfalse;|
  2438. |            if (w==3) print "^You are feeling a little tired.^";|
  2439. |            if (w==2) print "^You possessions are weighing you down.^";|
  2440. |            if (w==1) print "^Carrying so much weight is wearing you out.^";|
  2441. |            self.time_left = w;|
  2442. |       ];|
  2443. \endlines
  2444. Notice that items are actually dropped with |Drop| actions: one of them
  2445. might be, say, a wild boar, which would bolt away into the forest when
  2446. released.  The daemon tries to drop the heaviest item.  (Obviously a little
  2447. improvement would be needed if the game contained, say, an un-droppable
  2448. but very heavy ball and chain.)  Now the daemon is going to run every turn
  2449. forever, but needs to be started: so put |StartDaemon(weigher);| into the
  2450. game's |Initialise| routine.}
  2451. \medskip
  2452.  
  2453. A ``timer" (these are traditionally called ``^{fuses}" but the author can stand
  2454. only so much tradition) can alternatively be attached to an object.
  2455. (An object can't have both a |timer| and a |daemon| going at the same time.)
  2456. A timer is started with
  2457. \begintt
  2458. StartTimer(the-object, time);
  2459. \endtt^^{timers}^^|StartTimer|
  2460. in which case it will ``go off" (alarm clock-style) in the given number of
  2461. turns.  This means that its |time_out|
  2462. ^^|time out|
  2463. property will be called (as a routine), once and once only, when the time comes.
  2464.  
  2465. It can be deactivated (so that it will never go off) by calling
  2466. \begintt
  2467. StopTimer(the-object);
  2468. \endtt^^|StopTimer|
  2469.  
  2470. A timer is {\sl required} to provide a |time_left| property, to hold the
  2471. amount of time left.  If it doesn't, the library will print an error message
  2472. at run-time.  You can alter |time_left| yourself, but setting it to 0 does
  2473. not stop the timer: use the routine |StopTimer| for that.
  2474.  
  2475. \danger In early releases of the library, a |daemon| needed a |time_left|
  2476. as well, which was illogical and a nuisance: anyway, it's no longer the case.
  2477.  
  2478. \danger Normally, you can only have 32 timers or daemons active at the same
  2479. time as each other (there may be any number of inactive ones).  But this
  2480. limit is easily raised: just define the constant |MAX_TIMERS|
  2481. ^^|MAX TIMERS|
  2482. to some larger value, putting the definition in your code before the
  2483. |Parser| file is included.
  2484.  
  2485. \medskip
  2486. There is yet a third form of timed event.  If a room provides an |each_turn|
  2487. routine, then this will be called in each turn when the player is in it;
  2488. if an object provides |each_turn|, this is called whenever the object is
  2489. nearby.^^|each turn|  For instance, a ^{radio} might blare out music
  2490. whenever it is nearby; a ^{sword} might glow whenever monsters are nearby;
  2491. or a ^{stream} running through several forest locations might occasionally
  2492. float objects by.
  2493.  
  2494. `Each turn' is entirely separate from daemons and timers.  Although an object
  2495. can't have both a timer and a daemon at the same time, it can have an |each_turn|
  2496. at the same time, and this is quite useful, especially to run creatures.
  2497. An ^{ogre with limited patience} can therefore have an |each_turn| routine
  2498. which worries the player (``The ogre stamps his feet angrily!'', etc.)
  2499. while also having a timer set to go off when his patience runs out.
  2500.  
  2501. \danger  `Nearby' actually means `in scope', a term which will be properly
  2502. explained later.  The idea is based on ^{line of sight}, which works well
  2503. in most cases.
  2504.  
  2505. \ddanger  But it does mean that the radio will be inaudible when shut up
  2506. inside most containers - which is arguably fair enough - yet audible when
  2507. shut up inside transparent, say glass, ones.  You can always change the
  2508. scope rules using an |InScope| routine to get around this.  In case you
  2509. want to tell whether scope is being worked out for ordinary parsing reasons
  2510. or instead for |each_turn| processing, look at the |et_flag| variable
  2511. (0 in the former case, 1 in the latter).  Powerful effects are available
  2512. this way - you could put the radio in scope within all nearby rooms so as
  2513. to allow sound to travel.  Or you could make a thief audible throughout
  2514. the maze he is wandering around in, as in ^{`Zork I'}.
  2515. ^^|et flag|^^{audibility}^^{earshot}^^{thief in `Zork I'}
  2516. \bigskip
  2517.  
  2518. The library also has the (limited) ability to keep track of ^{time of day}
  2519. as the game goes on.
  2520.  
  2521. If you're writing a game with the time instead of the score and turns on the
  2522. status line, you can set the time by
  2523. \begindisplay
  2524. |SetTime(| 60$\times$\<hours>$+$\<minutes>|,| rate |);|
  2525. \enddisplay^^|SetTime|
  2526. The current time is held in the variable |the_time|
  2527. ^^|the time|
  2528. and runs on a 24-hour clock.  The |rate| controls how rapidly time is moving:
  2529. a |rate| of 0 means it is standing still (that is, that the library doesn't
  2530. change it: your routines still can).  A positive |rate| means that that many
  2531. minutes pass between each turn; and negative |rate| means that many turns
  2532. pass between each minute.
  2533.  
  2534. The time still won't appear on the game's status line unless you set
  2535. \begintt
  2536. Statusline time;
  2537. \endtt^^|Statusline|
  2538. as a directive somewhere in your code.  And remember to start off the clock
  2539. by calling |SetTime| in your ^|Initialise| routine, if you're going to use
  2540. it.
  2541.  
  2542. \exercise  How could you make your game take notice of the time passing
  2543. midnight, so that the day of the week could be nudged on?
  2544.                                                          
  2545. \answer{Either set a daemon to watch for |the_time| suddenly dropping, or
  2546. put such a watch in the game's |TimePasses| routine.}
  2547.  
  2548. \ninepoint
  2549. \danger  Exactly what happens at the end of each turn is:^^{time sequence}
  2550. \item{1.} The turns counter is incremented.
  2551. \item{2.} The 24-clock is moved on.
  2552. \item{3.} Daemons and timers are run (in no guaranteed order).
  2553. \item{4.} |each_turn| takes place for the current room, and then for
  2554. everything nearby (that is, in scope).
  2555. \item{5.} The game's global |TimePasses()| routine is called.
  2556. \item{6.} Light is re-considered (it may have changed as a result
  2557. of events since this time last turn).
  2558. \par\noindent
  2559. The sequence is abandoned if at any stage the player
  2560. dies or wins.\tenpoint
  2561.  
  2562. \dangerexercise  Suppose the player is magically suspended in mid-air,
  2563. but that anything let go of will fall out of sight.  The natural way
  2564. to code this is to use a daemon which gets rid of anything it finds
  2565. on the floor (this is better than just trapping |Drop| actions because
  2566. objects might end up on the floor in many different ways).  Why is
  2567. using |each_turn| better?^^{mid-air location}
  2568.  
  2569. \answer{Because you don't know what order daemons will run in.  A
  2570. `fatigue' daemon which makes the player drop something might come
  2571. after the `mid-air' daemon has run for this turn.  Whereas |each_turn|
  2572. happens after daemons and timers have run their course, and can fairly
  2573. assume no further movements will take place this
  2574. turn.^^{daemon running order}}
  2575.  
  2576. \exercise How would a game work if it involved a month-long
  2577. ^{archaeological dig}, where anything from days to minutes pass between
  2578. successive game turns?
  2579.  
  2580. \answer{It would have to provide its own code to keep track of time,
  2581. and it can do this by providing a |TimePasses()| routine.  Providing
  2582. ``time'' or even ``date'' verbs to tell the player would also be a
  2583. good idea.}
  2584.  
  2585. \section{15}{Adding verbs and grammar to the parser}
  2586.  
  2587. \poem
  2588. Grammar, which can govern even kings.
  2589. \poemby{^{Moli\`ere} (1622-1673)}{Les Femmes savantes}
  2590. \quote
  2591. Language disguises thought... The tacit conventions on which
  2592. the understanding of everyday language depends are enormously
  2593. complicated.
  2594. \poemby{^{Ludwig Wittgenstein}}{Tractatus}
  2595.  
  2596. The next few sections will delve deep into the ^{parser}.  Inform goes to
  2597. a great deal of trouble to make the parser as ``open-access'' as possible,
  2598. because a parser cannot ever be general enough for every game without
  2599. being extremely modifiable.  So there are very many ways to customise
  2600. the Inform parser, hopefully without the user needing to understand much
  2601. about how it works (because this is quite a long story).
  2602.  
  2603. The first essential requirement of any parser is to accept the addition of
  2604. the grammar for a new verb.  In Inform code, grammar should appear at the end
  2605. of the source code for a game, and of course most of it is written out
  2606. in the |Grammar| header file, which all games using the library include.
  2607. After this inclusion, you can add extras.^^{making grammar}
  2608.  
  2609. The directive for this is called ^|Verb|, and here's a typical example: some
  2610. of the library's grammar for ``take":^^{``take'' verb}
  2611. \beginlines
  2612. |Verb "take" "get" "pick" "lift"|
  2613. |                * "out"                          -> Exit|
  2614. |                * multi                          -> Take|
  2615. |                * multiinside "from" noun        -> Remove|
  2616. |                * "in" noun                      -> Enter|
  2617. |                * multiinside "off" noun         -> Remove|
  2618. |                * "off" held                     -> Disrobe|
  2619. |                * "inventory"                    -> Inv;|
  2620. \endlines
  2621. This declares a verb, for which ``take", ``get" and so on are synonyms, and
  2622. which can take seven different courses.
  2623.  
  2624. \danger It should be noted that these really are ^{synonyms}: the parser thinks
  2625. ``take" and ``get" are exactly the same.  Sometimes this has odd results,
  2626. so that although ``get in bed" is correctly understood as a request to enter
  2627. the bed, ``take in washing" is misunderstood as a request to enter the
  2628. washing.  You could either get around this by writing separate grammars for
  2629. the two nearly-synonyms, or can cheat and see if the variable
  2630. |verb_word=='take'| or |'get'|.  Mostly, though, you don't mind if a few
  2631. odd things are accepted by the parser: what matters more is that sensible
  2632. things are not rejected by it.
  2633.  
  2634. When it ploughs through what the player has typed, the parser tries to match
  2635. each line in turn, starting at the top.  The first line will only be matched
  2636. if the player has typed something like ``get out".  The second line is more
  2637. interesting: it allows the player to type a single object or a list of
  2638. objects.  So the second line could be matched by^^{grammar lines}
  2639. \begindisplay
  2640. take the banana\cr
  2641. get all the fruit except the apple\cr
  2642. \enddisplay
  2643. There need be no grammar at all after the verb: for example, a grammar for
  2644. ``inventory" could be as simple as
  2645. \begintt
  2646. Verb "invent" "inv" "i"
  2647.                 *                                -> Inv;
  2648. \endtt
  2649. After the ^|->| in each line is the name of an action.  This is how actions
  2650. are defined: they are the names which appear in grammar lines like this
  2651. one.  Remember that if you do create an action this way, you also have
  2652. to write a routine to execute the action, even if it's one which doesn't
  2653. do very much.  For instance:
  2654. \begintt
  2655. [ XyzzySub; "Nothing happens."; ];
  2656. Verb "xyzzy"    *                                -> Xyzzy;
  2657. \endtt
  2658. will make a new magic-word verb ``xyzzy'', which always says ``Nothing
  2659. happens'' - always, that is, unless some |before| rule gets there first,
  2660. as it might do in certain magic places.  (The name of the routine is
  2661. always the name of the action with |Sub| appended.)^^{``xyzzy'' verb}
  2662.  
  2663. The new action |Xyzzy| is treated exactly like all the standard Inform
  2664. actions: |##Xyzzy| gives its action number, and you can write |before|
  2665. and |after| rules for it in |Xyzzy:| fields just as you would for, say,
  2666. |Take|.
  2667.  
  2668. The individual words in the grammar (after the |*| and before the |->|) are
  2669. called ``tokens".  In increasing order of complexity, this is the complete
  2670. list:^^{grammar tokens}^^{tokens}
  2671. {\smallskip\baselineskip=7 true mm\settabs 8\columns
  2672. \+& |"|\<word>|"|   &&    that literal word only\cr
  2673. \+& \cstok{noun}          &&    any object in scope\cr
  2674. \+& \cstok{held}          &&    object held by the player\cr
  2675. \+& \cstok{creature}      &&    an object in scope which is |animate|\cr
  2676. \+& \cstok{multi}         &&    one or more objects in scope\cr
  2677. \+& \cstok{multiheld}     &&    one or more held objects\cr
  2678. \+& \cstok{multiexcept}   &&    one or more in scope, except the other\cr
  2679. \+& \cstok{multiinside}   &&    one or more in scope, inside the other\cr
  2680. \+& \<attribute>          &&    any object in scope which has the attribute\cr
  2681. \+& |noun = |\<Routine>   &&    any object in scope passing the given test\cr
  2682. \+& |scope = |\<Routine>  &&    an object in this definition of scope\cr
  2683. \+& \cstok{special}       &&    {\it any} single word or number\cr
  2684. \+& \cstok{number}        &&    a number only\cr
  2685. \+&   \<Routine>          &&    any text accepted by the given routine\cr
  2686. \smallskip\par\noindent}
  2687. (Tokens like \cstok{noun} are so written here to avoid confusion: there is
  2688. a variable called |noun| too, which is quite different.)
  2689. \par
  2690. In the case of |noun = |\<Routine>, the parser applies the following test:
  2691. the variable |noun| is set to the object in question, and the routine is
  2692. called.  If it returns true, the parser accepts the object, and otherwise
  2693. it rejects it.
  2694. \par \cstok{number} matches any decimal number from 0 upwards (though it
  2695. rounds off large numbers to 10000), and also matches the numbers ``one''
  2696. to ``twenty'' written in English.
  2697. \par The token \cstok{special} is now obselete.
  2698. \par For now, we shall take ``in scope" to mean ``visible to the player".  It
  2699. is quite important in some cases to know exactly what this means, so
  2700. a better definition will be given later.
  2701. ^^{noun token}^^{held token}^^{multiheld token}^^{multiexcept token}
  2702. ^^{creature token}^^{special token}^^{number token}
  2703.  
  2704. The \cstok{held} token is convenient for two reasons.  Firstly, many actions
  2705. only sensibly apply to things being held (such as |Eat| or |Wear|), and
  2706. using this token in the grammar you can make sure that the action is
  2707. never generated by the parser unless the object is being held.  That
  2708. saves on always having to write ``You can't eat what you're not holding"
  2709. code.  Secondly, suppose we have grammar
  2710. \begintt
  2711. Verb "eat"
  2712.                 * held                           -> Eat;
  2713. \endtt
  2714. and the player types
  2715. \begindisplay
  2716. eat the banana
  2717. \enddisplay
  2718. while the ^{banana} is plainly in view, on a shelf, say.  It would be
  2719. rather petty of the game to refuse on the grounds that the banana is
  2720. not being held.  So the parser will generate a |Take| action for the
  2721. banana and then, if the |Take| action succeeds, an |Eat| action.  (Notice
  2722. that the parser does not just pick up the object, but issues an action
  2723. in the proper way - so if the banana had rules making it too slippery
  2724. to pick up, it won't be picked up.)
  2725.  
  2726. The \cstok{multi-} tokens indicate that a list of one or more objects can
  2727. go here.  (The parser works out all the things the player has asked
  2728. for, sorting out plural nouns and words like ``except" by itself, and
  2729. then generates actions for each one.)  \cstok{multiexcept} is provided
  2730. to make commands like
  2731. \begindisplay
  2732. put everything in the rucksack
  2733. \enddisplay
  2734. parsable: the ``everything" is matched by all of the player's
  2735. possessions except the ^{rucksack} (this stops the parser from generating
  2736. an action to put the rucksack inside itself).  Similarly
  2737. \cstok{multiinside} handles:
  2738. \begindisplay
  2739. remove everything from the cupboard
  2740. \enddisplay
  2741. A restriction here is that a single grammar line can only contain
  2742. one \cstok{multi-} token: so ``hit everything with everything" can't be
  2743. parsed (straightforwardly: you can parse anything with a little more
  2744. effort).  On the whole, this is no bad thing.
  2745.  
  2746. The reason not all nouns can be multiple in the first place is that
  2747. too helpful a parser makes too easy a game.  You probably don't want
  2748. to allow something like
  2749. \begindisplay
  2750. unlock the mystery door with all the keys
  2751. \enddisplay
  2752. - you want the player to suffer having to try them one at a time,
  2753. or else to be thinking.  (Of course if you do want to allow this it
  2754. is easy enough to change the grammar: the point is that you have the
  2755. option.)
  2756. \medskip
  2757.  
  2758. We can also sort out objects according to attributes that they have:
  2759. \begintt
  2760. Verb "use" "employ" "utilise"
  2761.                 * edible                    -> Eat
  2762.                 * clothing                  -> Wear
  2763.       ...and so on...
  2764.                 * enterable                 -> Enter;
  2765. \endtt
  2766. and this is how attributes are used as tokens.  (The library grammar
  2767. does not contain such an ^{appallingly convenient verb}!)
  2768.  
  2769. Since you can define your own attributes, it is therefore easy to
  2770. make a grammar line which matches only your own class of object.
  2771.  
  2772. \danger A footnote: the \cstok{creature} token is thus equivalent to
  2773. writing |animate|; but it dates back to the earliest days of Inform,
  2774. and does no harm.
  2775.  
  2776. Sometimes even that isn't flexible enough.  Here is a verb, ``free",
  2777. which should only apply to animal kept in a cage:
  2778. \begintt
  2779. [ CagedCreature;
  2780.     if (noun in wicker_cage) rtrue; rfalse;
  2781. ];
  2782. Verb "free" "release"
  2783.                 * noun=CagedCreature        -> FreeAnimal;
  2784. \endtt^^{``free'' verb}
  2785. So that only nouns which pass the |CagedCreature| test are allowed.
  2786. (The |CagedCreature| routine can appear anywhere in the code, though
  2787. it's tidier to keep it nearby.)
  2788. \medskip
  2789.  
  2790. So far, all the tokens were to tell the parser which of the objects in scope
  2791. were acceptable.  Exactly what `in scope' means will be gone into later,
  2792. and so will the powerful |scope=...| token.  Here we next want the parser to
  2793. match things other than names of objects and prepositions like ``into".
  2794. The simplest useful case is of numbers, for example:
  2795. \begintt
  2796. Verb "type"
  2797.                 * number                    -> TypeNum;
  2798. \endtt
  2799. so that the TypeNum action will happen if the player types ``type 504''
  2800. or ``type seventeen''.
  2801.  
  2802. \exercise  (A beautiful feature stolen from ^{David M. Baggett}'s game
  2803. ^{`The Legend Lives'}, which uses it to great effect.)  Some games produce
  2804. ^{footnotes} every now and then.  Arrange matters so that these are
  2805. numbered |[1]|, |[2]| and so on in order of appearance, to be read by the
  2806. player when ``footnote 1'' is typed.
  2807.  
  2808. \answer{^^{footnotes}
  2809. \beginlines
  2810. |Constant MAX_FOOTNOTES 10;|
  2811. |global footnotes_seen data MAX_FOOTNOTES;|
  2812. |global footnote_count;|
  2813. |[ Note n i pn;|
  2814. |    for (i=0:i<footnote_count:i++)|
  2815. |        if (n==footnotes_seen->i) pn=i;|
  2816. |    if (footnote_count==MAX_FOOTNOTES) "** MAX_FOOTNOTES exceeded! **";|
  2817. |    if (pn==0) { pn=footnote_count++; footnotes_seen->pn=n; }|
  2818. |    print " [",pn+1,"]";|
  2819. |];|
  2820. |[ FootnoteSub n;|
  2821. |    if (noun>footnote_count)|
  2822. |    {   print "No footnote [",noun,"] has been mentioned.^"; rtrue; }|
  2823. |    if (noun==0) "Footnotes count upward from 1.";|
  2824. |    n=footnotes_seen->(noun-1);|
  2825. |    print "[",noun,"]  ";|
  2826. |    if (n==0) "This is a footnote.";|
  2827. |    if (n==1) "D.G.REG.F.D is inscribed around English coins.";|
  2828. |    if (n==2) "~Jackdaws love my big sphinx of quartz~, for example.";|
  2829. |];|
  2830. ||
  2831. |Verb "footnote" "note" * number              -> Footnote;|
  2832. \endlines
  2833. And then call, for instance, |Note(1);| to refer in the game to
  2834. the ``English coins'' footnote.}
  2835.  
  2836. \danger 
  2837. In fact, you're allowed to provide your own ^{number-parsing} routine, so
  2838. many sneaky possibilities are open here - Roman numerals, coordinates
  2839. like ``J4", long telephone numbers (which would be too large to fit into
  2840. integer variables in Inform), understanding English numbers and so on.
  2841. This takes the form
  2842. \begintt
  2843. [ ParseNumber buffer length;
  2844.   ...returning 0 if no match is made, or the number otherwise...
  2845. ];
  2846. \endtt
  2847. and examines the supposed ``number" held at the byte address |buffer|,
  2848. which is a row of ASCII characters of the given |length|.  If you declare
  2849. a ^|ParseNumber| routine, then the parser will always try this first when
  2850. trying to decode something as a number (and if it fails will fall back
  2851. on its own number-parsing routine).
  2852. \medskip
  2853.  
  2854. \ddanger For not-very-good internal reasons, |ParseNumber| can't return
  2855. 0 to mean the number zero.  Probably ^{``zero''} won't be needed too often,
  2856. but if it is you can always return some value like 1000 and code the
  2857. verb in question to understand this as 0.
  2858.  
  2859. \ddanger You can give a routine to parse anything:
  2860. \begintt
  2861. [ French w n; w=NextWord();
  2862.     if (w=='un' or 'une') n=1;
  2863.     if (w=='deux')        n=2;
  2864.     if (w=='trois')       n=3;
  2865.     if (w=='quatre')      n=4;
  2866.     if (w=='cinq')        n=5;
  2867.     if (n==0) return -1;
  2868.     parsed_number = n; return 1;
  2869. ];
  2870. \endtt
  2871. will detect ^{low numbers in French}, and could be used by something like:
  2872. \begintt
  2873. Verb "type"
  2874.                 * French                    -> TypeFrenchNum
  2875.                 * number                    -> TypeNum;
  2876. \endtt
  2877. The specification for such a routine is as follows: it is to use |NextWord|
  2878. (possibly several times) to look at the appropriate words which
  2879. the user has typed.  The variable ^|wn| (current word number) may also be
  2880. helpful.  The routine must return
  2881. \begindisplay
  2882. -1\quad if the user's input isn't understood,\cr
  2883. 1\quad if there is a numerical value resulting, or\cr
  2884. $n$\quad if object $n$ is understood.\cr
  2885. \enddisplay
  2886. In the case of a number, the actual value should be put into the variable
  2887. |parsed_number|.^^|parsed number|
  2888. On an unsuccessful match (returning -1) it doesn't matter what the final
  2889. value of |wn| is.  On a successful one it should be left pointing to the next
  2890. thing {\it after} what the routine understood.  (Since ^|NextWord| moves
  2891. |wn| on by one each time it is called, this happens automatically unless
  2892. the routine has read too far.)
  2893. \medskip
  2894.  
  2895. That's all about tokens: back to verb definition commands, because
  2896. some of the above examples are slightly contrived - they create wholly
  2897. new and unlikely verbs.  More often, one would want, say, a big array of
  2898. labelled buttons, any of which could be pushed.  So the verb for ``push"
  2899. ought to be extended, and for this the ^|Extend| directive is provided:
  2900. \begintt
  2901. Extend "push"
  2902.                 * Button                    -> PushButton;   
  2903. \endtt
  2904. A routine called |Button| could then be written to accept things like
  2905. \begindisplay
  2906. ``button j16",\quad ``d11",\quad ``a5 button".
  2907. \enddisplay
  2908. The point of |Extend| is that it is against the spirit of the library to
  2909. alter the standard library files - including the grammar table - unless
  2910. absolutely necessary.
  2911.  
  2912. \ddanger Actually, there's a better way to provide these buttons, so that
  2913. they work with any verb automatically, and that's to make a button object
  2914. with a |parse_name| routine which cunningly extracts the button number
  2915. as it parses: see the game ^{`Balances'} for an example of this.
  2916.  
  2917. Normally, extra lines of grammar are added at the bottom of those already
  2918. there.  This may not be what you want.  For instance, ``take" has a grammar
  2919. line
  2920. \begintt
  2921.                 * multi                     -> Take
  2922. \endtt
  2923. quite early on.  So if you want to add a grammar line which diverts
  2924. ``take something-edible" to a different action, like so:
  2925. \begintt
  2926.                 * edible                    -> Eat
  2927. \endtt
  2928. then it's no good adding this at the bottom of the |Take| grammar, because
  2929. the earlier line will always be matched first.  Thus, you really want
  2930. to insert your line at the top, not the bottom, in this case.  The right
  2931. command is
  2932. \begintt
  2933. Extend "take" first
  2934.                 * edible                    -> Eat;
  2935. \endtt
  2936. You might even want to actually replace the old grammar completely, not
  2937. just add a line or two.  For this, use^^{replacing grammar}
  2938. \begintt
  2939. Extend "push" replace
  2940.                 * Button                    -> PushButton;
  2941. \endtt
  2942. and now ``push" can be used only in this way.  To sum up, |Extend| can take
  2943. three keywords:
  2944. {\ninepoint\smallskip\settabs 8\columns
  2945. \+& ^|replace| && completely replace the old grammar with this one\cr
  2946. \+& ^|first|   && insert the new grammar at the top of the old one\cr
  2947. \+& ^|last|    && insert the new grammar at the bottom of the old one\cr
  2948. \smallskip}\par\noindent
  2949. with |last| being the default (which doesn't need to be said explicitly).
  2950.  
  2951. \danger  Another convenience is to define ^|meta| verbs - verbs which are not
  2952. really part of the game, such as ``save'', ``score'' and ``quit''.
  2953. (You probably want to add your own debugging commands as meta-verbs: if you
  2954. make them ordinary verbs, then they may work most of the time, but might be
  2955. interfered with by game rules, and will take up ``game time".)
  2956. To declare a verb as |meta|, just add the word after the command.
  2957. For instance, the library defines
  2958. \begintt
  2959. Verb meta "score"
  2960.                 *                           -> Score;
  2961. \endtt^^{``score'' verb}
  2962. The parser will match the grammar exactly in the normal way, but treats
  2963. the resulting action as outside the game - taking no time up, and
  2964. possible at any moment.
  2965.  
  2966. \ddanger There are (a few) times when verb definition commands are not
  2967. enough.  For example, in the original ^{`Advent'} (or ^{`Colossal Cave'}),
  2968. the player could type the name of a not-too-distant place which had
  2969. previously been visited, and be taken there.  There are several ways to code
  2970. this - say, with 60 rather similar verb definitions, or with a single
  2971. ``travel" verb which has 60 synonyms, whose action routine looks at the
  2972. parser's |verb_word| variable to see which one was typed - but here's
  2973. another.  The library will call the ^|UnknownVerb| routine (if you provide one)
  2974. when the parser can't even get past the first word.  This has two options:
  2975. it can return false, in which case the parser just goes on to complain as it
  2976. would have done anyway.  Otherwise, it can return a verb word which is
  2977. substituted for what the player actually typed.  Here is a foolish example:
  2978. \begintt
  2979. [ UnknownVerb w;
  2980.   if (w=='shazam') { print "Shazam!^"; return 'inventory'; }
  2981.   rfalse;
  2982. ];
  2983. \endtt^^{``shazam'' verb}^^{flexible verbs}
  2984. which responds to the magic word ``shazam" by printing |Shazam!| and then,
  2985. rather disappointingly, taking the player's inventory.  But in the example
  2986. above, it could be used to look for the word |w| through the locations of
  2987. the game, store the place away in some global variable, and then return |'go'|.
  2988. The |GoSub| routine could then be fixed to look at this variable.
  2989.  
  2990. \ddangerexercise  Why is it usually a bad idea to print text out in an
  2991. |UnknownVerb| routine?
  2992.  
  2993. \answer{Because the parser might go on to reject the line it's working on:
  2994. for instance, if the player typed ``inventory splurge'' then the message
  2995. ``Shazam!'' followed by a parser complaint will be somewhat unedifying.}
  2996.  
  2997. \ddanger If you allow a flexible collection of verbs (say, names of
  2998. spells or places) then you may want a single `dummy' verb to stand for
  2999. whichever is being typed.  This may make the parser produce strange
  3000. questions because it is unable to sensibly print the verb back at the
  3001. player, but you can fix this using the ^|PrintVerb| entry point (see
  3002. the Appendix).  See the exercise below.^^{parser questions}
  3003.  
  3004. \dangerexercise  A tricky one: code a spaceship whose control panel has five
  3005. sliding controls, each of which can be set to a numerical value, so that
  3006. the game looks like:^^{spaceship control panel}
  3007. \beginlines
  3008. |>look|
  3009. |Machine Room|
  3010. |There is a control panel here, with five slides, each of which can be|
  3011. |set to a numerical value.|
  3012. ||
  3013. |>push slide one to 5|
  3014. |You set slide number 1 to the value 5.|
  3015. ||
  3016. |>examine the first slide|
  3017. |Slide number 1 currently stands at 5.|
  3018. ||
  3019. |>set four to six|
  3020. |You set slide number 4 to the value 6.|
  3021. \endlines
  3022.  
  3023. \answer{Here goes: we could implement the buttons with five
  3024. separate objects, essentially duplicates of each other.  (And by using a
  3025. class definition, this wouldn't look too bad.)  But if there were
  3026. 500 slides this would be less reasonable.^^{spaceship control panel}
  3027. \beginlines
  3028. |[ ASlide w n;|
  3029. |   if (location~=Machine_Room)            !  Slides only make sense in|
  3030. |       return -1;                         !  the Machine Room|
  3031. |   w=NextWord();|
  3032. |   if (w=='slide') w=NextWord();|
  3033. |   n=0;|
  3034. |   if (w=='first' or 'one')   n=1;|
  3035. |   if (w=='second' or 'two')  n=2;|
  3036. |   if (w=='third' or 'three') n=3;|
  3037. |   if (w=='fourth' or 'four') n=4;|
  3038. |   if (w=='fifth' or 'five')  n=5;|
  3039. |   if (n==0) return -1;                   !  Failure!|
  3040. |   w=NextWord();|
  3041. |   if (w~='slide') wn--;                  !  Move word counter back to|
  3042. |                                          !  first misunderstood word|
  3043. |   parsed_number=n;|
  3044. |   return 1;                              !  Success!|
  3045. |];|
  3046. ||
  3047. |Global slide_settings data 10;            !  Ten bytes of data to hold|
  3048. |                                          !  five words for the settings|
  3049. |                                          !  (all initially zero)|
  3050. ||
  3051. |!  An interesting point here is that "noun" and "second" contain the|
  3052. |!  appropriate numbers, and not objects: this all happens automatically|
  3053. ||
  3054. |[ SetSlideSub;|
  3055. |   slide_settings-->(noun-1) = second;|
  3056. |   print_ret "You set slide number ", noun,|
  3057. |             " to the value ", second, ".";|
  3058. |];|
  3059. ||
  3060. |[ XSlideSub;|
  3061. |   print_ret "Slide number ", noun, " currently stands at ",|
  3062. |       slide_settings-->(noun-1), ".";|
  3063. |];|
  3064. ||
  3065. |Extend "set" first|
  3066. |           * ASlide "to" number                  -> SetSlide;|
  3067. |Extend "push" first|
  3068. |           * ASlide "to" number                  -> SetSlide;|
  3069. |Extend "examine" first|
  3070. |           * ASlide                              -> XSlide;|
  3071. \endlines}
  3072.  
  3073. \ddangerexercise  An even trickier one: write a parsing routine which will
  3074. accept any amount of text (including spaces, full stops and commas)
  3075. between double-quotes as a single token.^^{parsing quoted strings}
  3076.  
  3077. \answer{^^{parsing quoted strings}
  3078. The ^{blackboard} code in ^{`Toyshop'} contains just such a routine:
  3079. \beginlines
  3080. |Global from_char; Global to_char;|
  3081. |[ QuotedText i j f;|
  3082. |   i = parse->((++wn)*4-3);|
  3083. |   if (buffer->i=='"')|
  3084. |   {   for (j=i+1:j<=(buffer->1)+1:j++)|
  3085. |           if (buffer->j=='"') f=j;|
  3086. |       if (f==0) return -1;|
  3087. |       from_char = i+1; to_char=f-1;|
  3088. |       if (from_char>to_char) return -1;|
  3089. |       while (f> (parse->(wn*4-3))) wn++; wn++;|
  3090. |       return 1;|
  3091. |   }|
  3092. |   return -1;|
  3093. |];|
  3094. \endlines^^{quoted text}
  3095. Note that in the case of success, the word marker |wn| is moved beyond the
  3096. last word accepted (since the Z-machine automatically tokenises
  3097. a double-quote as a single word).  The routine then tells the parser it
  3098. has parsed a number, which is a white lie.  What it actually does is to
  3099. record the byte positions where the quoted text starts and finishes in
  3100. the raw text |buffer| so that an action routine can easily extract the
  3101. text and use it later.  (Note that |""| with no text inside is not
  3102. matched by this routine but only because the last |if| statement throws
  3103. out that one case.)^^{double-quote}^^{tokenisation}}
  3104.  
  3105. \ddangerexercise  And another: implement the Crowther and Woods feature
  3106. of moving from one room to another by typing its name, discussed above,
  3107. using a dummy verb and without using |Replace| to change any library
  3108. routines.^^{named rooms}
  3109.  
  3110. \answer{^^{named rooms}
  3111. Define two properties:
  3112. \beginlines
  3113. |Property place_name;|
  3114. |Property long to_places;|
  3115. \endlines
  3116. The scheme will work like this: a named room should have the |place_name|
  3117. property set to a single dictionary word; say, the Bedquilt cave could
  3118. be called |'bedquilt'|.  Then in any room, a list of those other rooms
  3119. which can be moved to in this way should appear in the |to_places| entry.
  3120. For instance,
  3121. \beginlines
  3122. |to_places Bedquilt Slab_Room Twopit_Room;|
  3123. \endlines
  3124. Now the code: see if a not-understood verb is a place name of a nearby room,
  3125. and if so store that room's object number in |goto_room|, converting
  3126. the verb to a dummy.
  3127. \beginlines
  3128. |Global goto_room = 0;|
  3129. |[ UnknownVerb word p i;|
  3130. |    p = location.&to_places; if (p==0) rfalse;|
  3131. |    for (i=0:(2*i)<location.#to_places:i++)|
  3132. |        if (word==(p-->i).place_name)|
  3133. |        {   goto_room = p-->i; return 'go#room';|
  3134. |        }|
  3135. |    rfalse;|
  3136. |];|
  3137. |[ PrintVerb word;|
  3138. |    if (word=='go#room')|
  3139. |    { print "go to "; PrintShortName(goto_room); rtrue; }|
  3140. |    rfalse;|
  3141. |];|
  3142. \endlines
  3143. (The supplied |PrintVerb| is icing on the cake: so the parser can
  3144. say something like ``I only understood you as far as wanting to go to
  3145. Bedquilt.'' if need be.)  It remains only to put in code
  3146. and grammar for the ^{dummy verb}:
  3147. \beginlines
  3148. |[ GoRoomSub;|
  3149. |    if (goto_room hasnt visited) "But you have never been there.";|
  3150. |    PlayerTo(goto_room);|
  3151. |];|
  3152. |Verb "go#room"  *                                -> GoRoom;|
  3153. \endlines
  3154. Note that if you don't know the way, you can't go there!  A purist might
  3155. prefer instead to not recognise the name of an unvisited room, back at
  3156. the |UnknownVerb| stage, to avoid the player being able to deduce names
  3157. of nearby rooms from this `error message'.}
  3158.  
  3159.  
  3160. \section{16}{Scope and what you can see}
  3161.  
  3162. \quote
  3163. He cannot see beyond his own nose.  Even the fingers he outstretches
  3164. from it to the world are (as I shall suggest) often invisible to him.
  3165. \quoteby{^{Max Beerbohm} (1872-1956), of ^{George Bernard Shaw}}
  3166. \poem
  3167. Wherefore are these things hid?
  3168. \poemby{^{William Shakespeare} (1564-1616)}{Twelfth Night}
  3169.  
  3170. Time to say what ``in scope" means.  This definition is one of the most
  3171. important algorithms in the game, although it is buried inside the parser,
  3172. because it decides what the player is allowed to refer to: so here it is
  3173. in full.  The following are in scope:^^{scope}^^{in scope}
  3174. \begindisplay
  3175. the player's immediate possessions;\cr
  3176. the 12 compass directions;\cr
  3177. {\bf if} there is light, the objects in the same place as the player.\cr
  3178. \enddisplay
  3179. {\par\narrower In addition, if an object is in scope then its immediate
  3180. possessions are in scope, {\bf if} it is ^{`see-through'}, which means that:}
  3181. \begindisplay
  3182. the object has |supporter|, {\bf or}\cr
  3183. the object has |transparent|, {\bf or}\cr
  3184. the object is an |open| |container|.\cr
  3185. \enddisplay
  3186.  
  3187. The definition of when there is light will be gone into in the next section.
  3188.  
  3189. \danger Many things are still in scope in a dark room - so the player can
  3190. still turn a lamp on if it's being carried.  On the other hand, a player who
  3191. puts the lamp on the ground and turns it off then loses the ability to
  3192. turn it back on again, because it is out of scope.  (This can be changed;
  3193. see below.)^^{darkness}
  3194.  
  3195. \danger The compass direction objects make sense as objects.  The player can
  3196. always type something like
  3197. \begindisplay
  3198. attack the south wall
  3199. \enddisplay
  3200. (and a |before| rule for the room in question could make something
  3201. unusual happen as a result).  The compass directions are visible in the
  3202. dark, as otherwise the player could not still walk around.
  3203.  
  3204. \danger The parser applies scope rules to other people too, not just the
  3205. player.  Thus ``dwarf, drop sword'' will be accepted even if the sword is
  3206. invisible to the player provided it is visible to the dwarf.
  3207.  
  3208. \danger Items with the ^|concealed| attribute may be concealed from
  3209. ordinary descriptions - but the parser still sees them: they are still in
  3210. scope.  (If you want things to be both concealed and unreferrable-to,
  3211. put them somewhere else!)
  3212.  
  3213. \ddanger Actually, the above definition is not quite right, because
  3214. the compass ^{directions} are not in scope when the player asks for a plural
  3215. number of things, like ``take all the knives".  (This makes some of the
  3216. parser's plural algorithms run faster.)  Also, for a \cstok{multiexcept}
  3217. token, the other object is not in scope; and for a \cstok{multiinside} token,
  3218. only objects in the other object are in scope.  This makes ``take everything
  3219. from the cupboard'' work in the natural way.
  3220. \medskip
  3221.  
  3222. The rest of this section is about how to change the scope rules.  As usual
  3223. with Inform, you can change them globally, but it's more efficient and
  3224. safer to do so only locally.
  3225.  
  3226. A typical example: how do we allow the player to ask questions like
  3227. the traditional
  3228. ^{``what is a grue''}^^{grues}^^{questions}^^{asking questions}?
  3229. The ``grue'' part ought to be parsed as if it were a noun, so that
  3230. we could distinguish between, say, a ``garden grue'' and a ``wild grue''.
  3231. So it isn't good enough to look only at a single word.  Here is one
  3232. solution:
  3233. \beginlines
  3234. |Object questions "qs";|
  3235. |[ QuerySub;|
  3236. |  print_paddr noun.description; new_line;|
  3237. |];|
  3238. |[ Topic i;|
  3239. |  if (scope_stage==1) rfalse;|
  3240. |  if (scope_stage==2)|
  3241. |  {   objectloop (i in questions) PlaceInScope(i);|
  3242. |      rtrue;|
  3243. |  }|
  3244. |  "At the moment, even the simplest questions confuse you.";|
  3245. |];|
  3246. \endlines
  3247. where the actual questions are themselves objects which belong to
  3248. the |questions| object, like so:
  3249. \beginlines
  3250. |Object q1 "long count" questions|
  3251. |  with name "long" "count",|
  3252. |       description "The Long Count is the great Mayan cycle of time, \|
  3253. |           which began in 3114 BC and will finish with the world's end \|
  3254. |           in 2012 AD.";|
  3255. \endlines^^{Long Count}^^|scope stage|
  3256. and we also have a grammar line:
  3257. \beginlines
  3258. |Verb "what"|
  3259. |                * "is"  scope=Topic              -> Query|
  3260. |                * "was" scope=Topic              -> Query;|
  3261. \endlines
  3262. (Note that the |questions| and |q1| objects are out of the game for every
  3263. other purpose.  The name ``qs'' doesn't matter; the individual questions
  3264. are named so that the parser might be able to say ``Which do you mean,
  3265. the long count or the short count?'' if the player just asked ``what
  3266. is the count''.)  Here's what happens: when the parser reaches
  3267. |scope=Topic|, it calls the |Topic| routine with the variable |scope_stage|
  3268. set to 1.  The routine should return 1 (true) if it is prepared to allow
  3269. multiple objects to be accepted here, and 0 (false) otherwise: as we don't
  3270. want ``what is everything'' to list all the questions and answers in the
  3271. game, we return false.
  3272.  
  3273. A little later on in its machinations, the parser again calls |Topic|
  3274. with |scope_stage| now set to 2.  |Topic| is now under an obligation to
  3275. tell the parser which objects are to be in scope.  It can call two
  3276. parser routines to do this.
  3277. \begintt
  3278. ScopeWithin(object)
  3279. \endtt
  3280. puts everything inside the object into scope, though not the object itself;
  3281. \begintt
  3282. PlaceInScope(object)
  3283. \endtt^^|PlaceInScope|
  3284. puts just a single object into scope.  It is perfectly legal to declare
  3285. something in scope that ``would have been in scope anyway": or even something
  3286. which is in a different room altogether from the actor concerned, say at the
  3287. other end of a telephone line.  Our scope routine |Topic| should then return
  3288. \item{0} (false) to carry on with the usual scope rules, so that everything
  3289. that would usually be in scope still is, and
  3290. \item{1} (true) to tell the parser not to put any more objects into scope.
  3291. \par\noindent
  3292. (So at |scope_stage| 2 it is quite permissible to do nothing but return false,
  3293. whereupon the usual rules apply.)  |Topic| returns true because it wants
  3294. only question topics to be in scope, not question topics together with
  3295. everything near the player.
  3296.  
  3297. If the player had typed ``what is the long count'', that would be all that
  3298. happens and all would be well.  On the other hand, if the player typed
  3299. ``what is the lgon cnout'' owing to a bout of dyslexia, the error message
  3300. which the parser would usually produce (``You can't see any such thing'')
  3301. would be unsatisfactory.  So if parsing failed at this token, then
  3302. |Topic| is called at |scope_stage| 3 to print out a suitable error
  3303. message.  (It must provide one.)
  3304.  
  3305. \danger The |scope=| notation is available only under Inform 5.4 and later.
  3306.  
  3307. \danger Note that |ScopeWithin(object)| extends the scope down through
  3308. its possessions according to the usual rules (i.e. depending on their
  3309. transparency, whether they're containers and so in).  The definition of
  3310. |Topic| above shows how to put just the direct possessions into scope.
  3311.  
  3312. \exercise Write a token which puts everything in scope, so that you could
  3313. have a debugging ^{``purloin'' verb} which could take anything (regardless
  3314. of where it was and the rules applying to it).
  3315.  
  3316. \answer{A slight refinement of such a ^{``purloin'' verb} is already defined
  3317. in the library (if the constant |DEBUG| is defined), so there's no need.
  3318. Here's how it could be done:
  3319. \beginlines
  3320. |[ Anything i;|
  3321. |  if (scope_stage==1) rfalse;|
  3322. |  if (scope_stage==2)|
  3323. |  {   for (i=1:i<=top_object:i++) PlaceInScope(i); rtrue; }|
  3324. |  "No such in game.";|
  3325. |];|
  3326. \endlines^^{token for `any object'}
  3327. (This disallows multiple matches for efficiency reasons - the parser has
  3328. enough work to do with such a huge scope definition as it is.)  Now
  3329. the token |scope=Anything| will match anything at all, even things like
  3330. the abstract concept of `east'.}
  3331.  
  3332. \bigskip
  3333. Changing the global definition of scope should be done cautiously
  3334. (there may be unanticipated side effects); bear in mind that scope decisions
  3335. need to be taken often - every time an object token is parsed, so perhaps
  3336. five to ten times in every game turn - and hence moderately
  3337. quickly.^^{changing scope}
  3338.  
  3339. To do this one provides a routine called
  3340. \begintt
  3341. InScope(actor)
  3342. \endtt
  3343. where the ^|actor| is the person whom the parser is working out scope for;
  3344. usually, then, |actor=player|, but this should not be assumed to be always
  3345. the case.  If the routine decides that a particular object should be in
  3346. scope for the actor, it should execute |InScope| and |ScopeWithin| just
  3347. as above, and return true or false (as if it were at |scope_stage| 2).
  3348. Thus, it is vital to return false in circumstances when you don't want
  3349. to intervene.
  3350.  
  3351. \danger In the case of a token |scope=Routine|, the |Routine| gets first
  3352. crack at scope-changing, and |InScope| will only be reached if it returns
  3353. false to signify `carry on'.
  3354.  
  3355. Here are some examples.  Firstly, as promised above, how to change the
  3356. rule that ``things you've just dropped disappear in the dark":
  3357. \beginstt
  3358. [ InScope person i;
  3359.   if (person==player && location==thedark)
  3360.       objectloop (i near player)
  3361.           if (i has moved)
  3362.               PlaceInScope(i);
  3363.   rfalse;
  3364. ];
  3365. \endtt
  3366. With this routine added, the objects in the dark room the player
  3367. is in are in scope only if they have ^|moved| (that is, have been held by
  3368. the player in the past); and even then, are in scope only to the player.
  3369.  
  3370. \dangerexercise Code the following puzzle, which has nasty scope
  3371. complications.  In an initially dark room there is a ^{light switch}.
  3372. Provided you've seen the switch at some time in the past, you can turn
  3373. it on and off - but before you've ever seen it, you can't.  Inside the
  3374. room is nothing you can see, but you can hear a dwarf breathing.  If you
  3375. tell the dwarf to turn the light on, he will.
  3376.  
  3377. \answer{For good measure, we'll combine this with the previous rule
  3378. about |moved| objects being in scope in the dark.  The following
  3379. can be inserted into the `Shell' game:^^{light switch}
  3380. \beginlines
  3381. |Object coal "dull coal" Blank_Room|
  3382. |  with name "dull" "coal";|
  3383. ||
  3384. |Object Dark_Room "Dark Room"|
  3385. |  with description "An empty room with a west exit.",|
  3386. |       each_turn|
  3387. |       [; if (self has general) self.each_turn=0;|
  3388. |          else "^You hear the breathing of a dwarf.";|
  3389. |       ],|
  3390. |       w_to Blank_Room;|
  3391. ||
  3392. |Nearby light_switch "light switch"|
  3393. |  with name "light" "switch",|
  3394. |       initial "On one wall is the light switch.",|
  3395. |       after|
  3396. |       [; SwitchOn: give Dark_Room light;|
  3397. |          SwitchOff: give Dark_Room ~light;|
  3398. |       ],|
  3399. |  has  switchable static;|
  3400. ||
  3401. |Nearby diamond "shiny diamond"|
  3402. |  with name "shiny" "diamond"|
  3403. |  has  scored;|
  3404. ||
  3405. |Nearby dwarf "dwarf"|
  3406. |  with name "voice" "dwarf",|
  3407. |       life|
  3408. |       [; Order: if (action==##SwitchOn && noun==light_switch)|
  3409. |                 {   give Dark_Room light general;|
  3410. |                     give light_switch on; "~Right you are, squire.~";|
  3411. |                 }|
  3412. |       ],|
  3413. |  has  animate;     |
  3414. ||
  3415. |[ InScope person i;|
  3416. |  if (parent(person)==Dark_Room)|
  3417. |  {   if (person==dwarf || Dark_Room has general)|
  3418. |          PlaceInScope(light_switch);|
  3419. |  }|
  3420. |  if (person==player && location==thedark)|
  3421. |      objectloop (i near player)|
  3422. |          if (i has moved || i==dwarf)|
  3423. |              PlaceInScope(i);|
  3424. |  rfalse;|
  3425. |];|
  3426. \endlines
  3427. Note that the routine puts the light switch in scope for the dwarf -
  3428. if it didn't, the dwarf would not be able to understand
  3429. ``dwarf, turn light on", and that was the whole point.}
  3430.      
  3431.  
  3432. \danger By combining an |InScope| routine with token-parsing routines
  3433. in grammar, ^{dramatic effects} are possible.  See the example game
  3434. `Balances', for instance.
  3435.  
  3436. \ddanger Once you begin programming the parser on a large scale, you soon
  3437. reach the point where the parser's ordinary error messages no longer appear
  3438. sensible.  So that you can change the rules even at this last hurdle,
  3439. the parser calls your ^|ParserError| routine (if you provide one): the
  3440. argument is the error type, and you return true
  3441. to tell the parser to shut up (as you have already printed a better error
  3442. message than it would have done).  The error types are all defined as
  3443. constants:
  3444.  
  3445. {\ninepoint
  3446. \settabs 8\columns
  3447. \+&  |STUCK_PE|     &&   I didn't understand that sentence.\cr
  3448. \+&  |UPTO_PE |     &&   I only understood you as far as...\cr
  3449. \+&  |CANTSEE_PE|   &&   You can't see any such thing.\cr
  3450. \+&  |TOOLIT_PE|    &&   You seem to have said too little!\cr
  3451. \+&  |NOTHELD_PE|   &&   You aren't holding that!\cr
  3452. \+&  |MULTI_PE|     &&   You can't use multiple objects with that verb.\cr
  3453. \+&  |MMULTI_PE|    &&   You can only use multiple objects once on a line.\cr
  3454. \+&  |VAGUE_PE|     &&   I'm not sure what ~it~ refers to.\cr
  3455. \+&  |EXCEPT_PE|    &&   You excepted something not included anyway!\cr
  3456. \+&  |ANIMA_PE|     &&   You can only do that to something animate.\cr
  3457. \+&  |VERB_PE|      &&   That's not a verb I recognise.\cr
  3458. \+&  |SCENERY_PE|   &&   That's not something you need to refer to...\cr
  3459. \+&  |ITGONE_PE|    &&   You can't see ~it~ (the spell book) at the moment.\cr
  3460. \+&  |JUNKAFTER_PE| &&   I didn't understand the way that finished.\cr
  3461. \+&  |TOOFEW_PE|    &&   Only five of those are available.\cr
  3462. \+&  |NOTHING_PE|   &&   Nothing to do!\cr
  3463. \+&  |NUMBER_PE|    &&   I didn't understand that number.\cr
  3464. \+&  |ASKSCOPE_PE|  &&   {\it whatever the scope routine prints}\cr
  3465. \smallskip\par\noindent
  3466. Each time the parser gives up on a line of grammar, it has hit one of these
  3467. conditions.  A verb may have many lines of grammar; so by the time the
  3468. parser wants to print an error, all of them must have failed.  The error
  3469. message it prints is the most `interesting' one (meaning, lowest down this
  3470. list).}
  3471.  
  3472.  
  3473. \section{17}{The light and the dark}
  3474.  
  3475. \noindent^^{light and dark}^^{definition of darkness}^^{C. P. Snow}
  3476. The library maintains light by itself, and copes with events like:
  3477. \begindisplay
  3478. a total eclipse of the Sun;\cr
  3479. fusing all the lights in the house;\cr
  3480. your lamp going out;\cr
  3481. a dwarf stealing it and running away;\cr
  3482. dropping a lit match which you were seeing by;\cr
  3483. putting your lamp into an opaque box and shutting the lid;\cr
  3484. black smoke filling up the glass jar that the lamp is in;\cr
  3485. the dwarf with your lamp running back into your now-dark room.\cr
  3486. \enddisplay
  3487. The point of this list is to demonstrate that light v. darkness is
  3488. tricky to get right, and that it is best left to the library.  Your code
  3489. needs only to do something like
  3490. \begintt
  3491. give lamp light;
  3492. remove match;
  3493. give glass_jar ~transparent;
  3494. move dwarf to Dark_Room;
  3495. \endtt
  3496. and can leave the library to sort out the consequences.  As the above
  3497. suggests, the |light| attribute means that an object is giving off light,
  3498. or that a room is currently lit (e.g. by being out of doors in day-time).
  3499.  
  3500. If you simply never want to have darkness, and some games never do, a
  3501. sneaky way of doing it is to put the line
  3502. \begintt
  3503. give player light;
  3504. \endtt
  3505. in |Initialise|.  The game works as if the player herself were glowing
  3506. enough to provide light to see by.  So there's never darkness near the
  3507. player.
  3508. \medskip
  3509.  
  3510. The definition of ``when there is light" is complicated, involving
  3511. recursion both up and down.  Remember that the parent of the player
  3512. object may not be a room; it may be, say, a red car whose parent is a
  3513. room.
  3514.  
  3515. There is light exactly when the parent of the player `offers light'.
  3516. An object ^{`offers light'} if:
  3517. \begindisplay
  3518. it itself has the |light| attribute set, {\bf or}\cr
  3519. any of its immediate possessions `have light', {\bf or}\cr
  3520. it is see-through and its parent offers light, {\bf or}\cr
  3521. it is enterable and its parent offers light;\cr
  3522. \enddisplay
  3523. while an object ^{`has light'} if:
  3524. \begindisplay
  3525. it currently has the |light| attribute set, {\bf or}\cr
  3526. it is see-through and one of its immediate possessions has light.\cr
  3527. \enddisplay
  3528. The process of checking this stops as soon as light is discovered.  The
  3529. routines
  3530. \begindisplay
  3531. ^|OffersLight(object)| and ^|HasLightSource(object)|
  3532. \enddisplay
  3533. which return true or false and have no side effects (that is, they merely
  3534. report on the current state without changing anything), are available and
  3535. might occasionally be useful.
  3536.  
  3537. \danger So light is cast up and down the tree of objects.  In certain
  3538. contrived circumstances this might be troublesome: perhaps an opaque box,
  3539. whose outside is fluorescent but whose interior is dark, and which contains
  3540. an actor who needs not to have other contents of the box in scope...
  3541. `contrived' being the word.  The dilemma could be solved by putting an inner
  3542. box in the outer one.
  3543.  
  3544. \exercise  How would you code a ^{troll} who is afraid of the dark, and needs
  3545. to be bribed but will only accept a light source... so that the troll will
  3546. be as happy with a goldfish bowl containing a ^{fluorescent jellyfish} as he
  3547. would be with a lamp?
  3548.  
  3549. \answer{Just test if |HasLightSource(gift)==1|.}
  3550.  
  3551. Each turn, light is reconsidered.  The presence or absence of light affects
  3552. the |Look|, |Search|, |LookUnder| and |Examine| actions, and
  3553. (since this is a common puzzle) also the |Go| action: you can provide
  3554. a routine called
  3555. \begintt
  3556. DarkToDark()
  3557. \endtt^^|DarkToDark|
  3558. and if you do then it will be called when the player goes from one dark
  3559. room into another dark one.  If you want, you can take the opportunity to
  3560. kill the player off or extract some other forfeit.  If you provide no such
  3561. routine, then the player can move about freely (subject to any rules which
  3562. apply in the places concerned).
  3563.  
  3564.  
  3565. \section{18}{On inventories and lists}
  3566.  
  3567. \widepoem
  3568. As some day it may happen that a victim must be found
  3569. I've got a little list - I've got a little list
  3570. Of society offenders who might well be underground,
  3571. And who never would be missed
  3572. Who never would be missed!
  3573. \poemby{^{W. S. Gilbert} (1836-1911)}{The Mikado}
  3574.  
  3575. The library often needs to reel off a list of objects: when an |Inv|
  3576. (inventory) action takes place, for instance, or when describing the
  3577. contents of a container or a room.  Lists are difficult to print out
  3578. correctly `by hand', because there are many cases to get right (especially
  3579. when taking plurals into account).  Fortunately, the library's list-maker is
  3580. open to the public.  The routine to call is:^^{listing objects}
  3581. \begintt
  3582. WriteListFrom(object, style);
  3583. \endtt^^|WriteListFrom|
  3584. where the list will start from the given object and go along its siblings.
  3585. (Thus, to list all the objects inside |X|, list from |child(X)|.)  What the
  3586. list looks like depends on the style, which is a bitmap you can make by
  3587. adding up some of the following constants:^^{style of list}
  3588. \smallskip
  3589. \settabs 8\columns
  3590. \+&  |NEWLINE_BIT| &&   New-line after each entry\cr
  3591. \+&  |INDENT_BIT|  &&   Indent each entry by depth\cr
  3592. \+&  |FULLINV_BIT| &&   Full inventory information after entry\cr
  3593. \+&  |ENGLISH_BIT| &&   English sentence style, with commas and `and'\cr
  3594. \+&  |RECURSE_BIT| &&   Recurse downwards with usual rules\cr
  3595. \+&  |ALWAYS_BIT|  &&   Always recurse downwards\cr
  3596. \+&  |TERSE_BIT|   &&   More terse English style\cr
  3597. \+&  |PARTINV_BIT| &&   Only brief inventory information after entry\cr
  3598. \+&  |DEFART_BIT|  &&   Use the definite article in list\cr
  3599. \+&  |WORKFLAG_BIT| &&  At top level (only), only list objects\cr
  3600. \+&                &&   which have the |workflag| attribute\cr
  3601. \smallskip
  3602. \noindent The best way to use this is to experiment.   For example, a `tall'
  3603. inventory is produced by:
  3604. \begintt
  3605. WriteListFrom( child(player),
  3606.                FULLINV_BIT + INDENT_BIT + NEWLINE_BIT + RECURSE_BIT );
  3607. \endtt^^{narrow inventory}
  3608. and a `wide' one by:
  3609. \begintt
  3610. WriteListFrom( child(player),
  3611.                FULLINV_BIT + ENGLISH_BIT + RECURSE_BIT );
  3612. \endtt^^{wide inventory}
  3613. which produce effects like:
  3614. \beginstt
  3615. >inventory tall
  3616. You are carrying:
  3617.   a bag (which is open)
  3618.     three gold coins
  3619.     two silver coins
  3620.     a bronze coin
  3621.   four featureless white cubes
  3622.   a magic burin
  3623.   a spell book
  3624. \endtt\beginstt
  3625. >inventory wide
  3626. You are carrying a bag (which is open), inside which are three gold
  3627. coins, two silver coins and a bronze coin, four featureless white
  3628. cubes, a magic burin and a spell book.
  3629. \endtt
  3630. (except that the `You are carrying' part is not done by the list-maker,
  3631. and nor is the final full stop in the second example).
  3632. \medskip
  3633.  
  3634. The |workflag| is an attribute which the library scribbles over from time
  3635. to time as temporary storage, but you can use it with care.  In this case
  3636. it makes it possible to specify any reasonable list.
  3637.  
  3638. \exercise Write a |DoubleInvSub| action routine to produce an inventory
  3639. like so:^^{double inventory}
  3640. \beginstt
  3641. You are carrying four featureless white cubes, a magic burin and a
  3642. spell book.  In addition, you are wearing a purple cloak and a miner's
  3643. helmet.
  3644. \endtt
  3645.  
  3646. \answer{\beginlines
  3647. |[ DoubleInvSub i count1 count2;|
  3648. |  print "You are carrying ";|
  3649. |  objectloop (i in player)|
  3650. |  {   if (i hasnt worn) { give i workflag; count1++; }|
  3651. |      else { give i ~workflag; count2++; }|
  3652. |  }|
  3653. |  if (count1==0) print "nothing.";|
  3654. |  else|
  3655. |  WriteListFrom(child(player),|
  3656. |      FULLINV_BIT + ENGLISH_BIT + RECURSE_BIT + WORKFLAG_BIT);|
  3657. ||
  3658. |  if (count2==0) ".";|
  3659. |  print ".  In addition, you are wearing ";|
  3660. |  objectloop (i in player)|
  3661. |  {   if (i hasnt worn) give i ~workflag; else give i workflag;|
  3662. |  }|
  3663. |  WriteListFrom(child(player),|
  3664. |      ENGLISH_BIT + RECURSE_BIT + WORKFLAG_BIT);|
  3665. |  ".";|
  3666. |];|
  3667. \endlines^^{double inventory}}
  3668.  
  3669. Some objects ought to print something different when they appear in
  3670. inventory lists: a wine bottle should say how much wine is left, for
  3671. instance.  By giving an object an ^|invent| routine, you can alter the
  3672. usual rules.
  3673.  
  3674. A typical inventory list looks like:
  3675. \beginstt
  3676. >i
  3677. You are carrying:
  3678.   a green cone
  3679.   a pair of hiking boots
  3680.   your satchel (which is open)
  3681.     a green cube
  3682. \endtt
  3683. and each line goes through two stages.  Firstly, the object's indefinite
  3684. article and name are printed.  Secondly, little informative messages like
  3685. ``(which is open)" are printed, and ^{inventories} are given for the contents
  3686. of open containers.
  3687.  
  3688. An object's |invent| routine gets two chances to interfere with this,
  3689. one before each stage.  So what happens is this:
  3690. \item{1.}  The global variable |inventory_stage| is set to 1.
  3691. \item{2.}  The |invent| routine is called (if there is one).
  3692. If it returns true, stop here.
  3693. \item{3.}  The indefinite article and short name are printed.
  3694. \item{4.}  The global variable |inventory_stage| is set to 2.
  3695. \item{5.}  The |invent| routine is called (if there is one).
  3696. If it returns true, go to step 8.
  3697. \item{6.}  One or more of the following are printed, as appropriate:
  3698. \begindisplay
  3699. \quad (providing light)\cr
  3700. \quad (being worn)\cr
  3701. \quad (which is open)\cr
  3702. \quad (which is closed)\cr
  3703. \enddisplay
  3704. \item{7.}  If it is an open container, its contents are inventoried.
  3705. \item{8.}  Linking text (such as a new-line or a comma) is printed,
  3706. according to the current style.^^|inventory stage|
  3707. \par\noindent Note that if an |invent| routine does return true,
  3708. then the contents are never reached.
  3709.  
  3710. For example, here is an |invent| routine for a ^{matchbook}:
  3711. \beginstt
  3712. invent
  3713. [ i; if (inventory_stage==2)
  3714.      {   i=self.number;
  3715.          if (i==0) print " (empty)";
  3716.          if (i==1) print " (1 match left)";
  3717.          if (i>1)  print " (",i," matches left)";
  3718.      }
  3719. ],
  3720. \endtt
  3721. (The rest of the matchbook definition is given in the ^{`Toyshop'} example
  3722. game.)
  3723.  
  3724. \ddanger Changing the rules at |inventory_stage| 1 is kept on for more
  3725. peculiar effects (and is not really recommended).
  3726.  
  3727.  
  3728. \section{19}{The naming of names}
  3729.  
  3730. \verywidepoem
  3731. The Naming of Cats is a difficult matter,
  3732. It isn't just one of your holiday games;
  3733. You may think at first I'm as mad as a hatter
  3734. When I tell you, a cat must have THREE DIFFERENT NAMES.
  3735. \poemby{^{T. S. Eliot} (1888-1965)}{The Naming of Cats}
  3736.  
  3737. \quote
  3738. Bulldust, coolamon, dashiki, fizgig, grungy, jirble, pachinko,
  3739. poodle-faker, sharny, taghairm
  3740. \quoteby{Catachrestic words from Chambers English Dictionary}
  3741.  
  3742. Providing an |invent| routine doesn't work quite so well for the match
  3743. as for the matchbook.  You might try:
  3744. \beginstt
  3745. invent
  3746. [;   if (inventory_stage==2)
  3747.      {   if (self has light) print " (burning away)"; rtrue;
  3748.      }
  3749. ],
  3750. \endtt
  3751. \danger Returning true here is a trick to stop ``(providing light)"
  3752. from appearing as well - after all, that's redundant.
  3753.  
  3754. This does work but there's a better way, which is to change the object's
  3755. short name itself, from ``unlit match" to ``lit match" say.  So
  3756. another property, called |short_name|, is available.
  3757. ^^|short name|  Normally, the short name of an object
  3758. is given in the header of the object definition.
  3759. But if a |short_name| routine is given, then whenever the game wants to
  3760. write out the name of the object, the following happens:
  3761. \item{1.} If the |short_name| is a string, it's printed and that's all.
  3762. \item{2.} If it is a routine, then it is called.  If it returns true,
  3763. that's all.
  3764. \item{3.} The `real' short name (the one in the object header) is printed.
  3765. \par\noindent So, as promised, here's the better way to code the match:
  3766. \beginstt
  3767. short_name
  3768. [;   if (self has light) print "burning match";
  3769.                     else print "unlit match";
  3770.      rtrue;
  3771. ],
  3772. \endtt
  3773. Note that rooms can also be given a |short_name| routine, which might be
  3774. useful to code, say, a grid of four hundred almost exactly similar
  3775. locations, called ``Area 1" up to ^{``Area 400"}.
  3776. \medskip
  3777.  
  3778. \danger Now, though, the player is going to want to type ``drop the
  3779. burning match", or ``light the unlit match".  (Indeed, there might be two 
  3780. matches, only one of which can be called ``unlit".)  It's perfectly
  3781. straightforward to alter the ^|name| property of an object (provided one
  3782. remembers what it is: a list of (machine) words, being the byte addresses in
  3783. memory of words in the dictionary) but, again, there is a better and more
  3784. powerful way. This is to give the match object a |parse_name| routine.
  3785.  
  3786. \ninepoint^^|parse name|
  3787. A |parse_name| routine is expected to try to match the text which the user
  3788. has typed (available one word at a time from the |NextWord()| routine), and
  3789. to return how many words it managed to match.  It is required to go as far
  3790. as it can, i.e., not to stop if the first word makes sense, but to keep
  3791. reading and find out how many words in a row make sense.
  3792.  
  3793. It should return:
  3794. \begindisplay
  3795. 0\quad    if the text didn't make any sense at all,\cr
  3796. $k$\quad  if $k$ words in a row of the text seem to refer to the object, or\cr
  3797. -1\quad   to make the parser just do what it would normally do.\cr
  3798. \enddisplay
  3799. For example:
  3800. \beginstt
  3801. Nearby thing "weird thing"
  3802.   with parse_name
  3803.        [ i; while (NextWord()=='weird' or 'thing') i++;
  3804.             return i;
  3805.        ];
  3806. \endtt^^{weird thing}
  3807. This definition duplicates (very nearly) what the parser would have done
  3808. if the weird thing had been defined as:
  3809. \beginstt
  3810. Nearby thing "weird thing"
  3811.   with name "weird" "thing";
  3812. \endtt
  3813. Which isn't very useful.  But the match can now be coded up with
  3814. \beginstt
  3815. parse_name
  3816. [ i j;   if (self has light) j='burning'; else j='unlit';
  3817.          while (NextWord()=='match' or j) i++;
  3818.          return i;
  3819. ],
  3820. \endtt       
  3821. so that ``burning" only applies when it is, and similarly ``unlit".
  3822. (Actually the parser automatically recognises ``unlit" and ``lit", so this
  3823. last part was unnecessary.)
  3824. \tenpoint
  3825.  
  3826.  
  3827. \section{20}{Plural names and groups of similar objects}
  3828.  
  3829. \poem
  3830. Abiit ad plures.
  3831. \poemby{Petronius (?-c. 66)}{Cena Trimalchionis}
  3832.  
  3833. A notorious problem for adventure game parsers is to handle a collection of,
  3834. say, ten gold coins, allowing the player to use them independently of each
  3835. other, while gathering them together into groups in descriptions and
  3836. inventories.  This is relatively easy in Inform, and only in really hard
  3837. cases do you have to provide code.^^{plural objects}
  3838.  
  3839. There are two problems to be overcome: firstly, the game has to be able
  3840. to talk to the player in plurals, and secondly vice versa.  First, then,
  3841. game to player:
  3842. \beginstt
  3843. Class  gold_coin_class
  3844.   with name "gold" "coin",
  3845.        plural "gold coins";
  3846. \endtt
  3847. \noindent (and similar silver and bronze coin classes here)
  3848. \beginstt
  3849. Object bag "bag"
  3850.   with name "bag"
  3851.   has  container open openable;
  3852. \endtt\beginstt
  3853. Nearby co1 "gold coin"   class gold_coin_class;
  3854. Nearby co2 "gold coin"   class gold_coin_class;
  3855. Nearby co3 "gold coin"   class gold_coin_class;
  3856. Nearby co4 "silver coin" class silver_coin_class;
  3857. Nearby co5 "silver coin" class silver_coin_class;
  3858. Nearby co6 "bronze coin" class bronze_coin_class;
  3859. \endtt
  3860. \noindent Now we have a ^{bag of six coins}.  The player looking inside
  3861. the bag will get
  3862. \beginstt
  3863. >look inside bag
  3864. In the bag are three gold coins, two silver coins and a bronze coin.
  3865. \endtt
  3866. How does the library know that the three gold coins are the same as each
  3867. other, but the others different?  It doesn't look at the classes but the
  3868. names.  It will only group together things which:
  3869. \item{(a)}  have a ^|plural| set,
  3870. \item{(b)}  are ^{`indistinguishable'} from each other.
  3871.  
  3872. \noindent Indistinguishable means they have the same |name| words as each other
  3873. (possibly in a different order), so that nothing the player can type
  3874. will separate the two.
  3875.  
  3876. \danger Actually, the library is cleverer than this.  What it groups
  3877. together depends slightly on the context of the list it's writing out.  When
  3878. it's writing a list which prints out details of which objects are providing
  3879. light, for instance (like an inventory), it won't group together two objects
  3880. if one is lit and the other isn't.  Similarly for objects with visible
  3881. possessions or which can be worn.
  3882.  
  3883.  
  3884. \ddanger This all gets even more complicated when the objects have a
  3885. |parse_name| routine supplied, because then the library can't use the |name|
  3886. fields to tell them apart.  If they have different |parse_name| routines, it
  3887. decides that they're different.  But if they have the same |parse_name|
  3888. routine, there is no alternative but to ask them.  What happens is that
  3889. \begindisplay
  3890. 1.\quad A variable called |parser_action| is set to |##TheSame|;\cr
  3891. 2.\quad Two variables, called |parser_one| and |parser_two| are set to\cr
  3892. \phantom{2.}\quad the two objects in question;\cr
  3893. 3.\quad Their |parse_name| routine is called.  If it returns:\cr
  3894. \qquad -1 \quad the objects are declared ``indistinguishable",\cr
  3895. \qquad -2 \quad they are declared different.\cr
  3896. 4.\quad Otherwise, the usual rules apply and the library looks at\cr
  3897. \qquad the ordinary |name| fields of the objects.\cr
  3898. \enddisplay^^{fake actions}^^|parser one, parser two, parser action|
  3899. (|##TheSame| is a fake action.)
  3900. ^^|TheSame|
  3901.   The implementation of the
  3902. ^{`Spellbreaker cubes'} in the ^{`Balances'} game
  3903. is an example of such a routine (so that if
  3904. the player writes the same name on several of the cubes, they become
  3905. grouped together).  Note that this whole set-up is such that if the
  3906. author of the |parse_name| routine has never read this paragraph, it doesn't
  3907. matter and the usual rules take their course.^^|parse name|
  3908.  
  3909. \ddanger You may even want to provide a |parse_name| routine just to speed
  3910. up the process of telling two objects apart - if there were 30 gold coins
  3911. the parser will be doing a lot of work comparing all their names, but you
  3912. can make the decision much faster.
  3913. \bigskip
  3914.  
  3915. Secondly, the player talking to the computer.  This goes a little further
  3916. than just copies of the same object: many games involve collecting a number
  3917. of similar items, say a set of nine crowns in different colours. Then you'd
  3918. want the parser to recognise things like:
  3919. \begintt
  3920. > drop all of the crowns except green
  3921. > drop the three other crowns
  3922. \endtt
  3923. even though the ^{crowns} are not identical.  The simple way to do this is just
  3924. to put |"crowns"| in their name fields, and this works perfectly well most of
  3925. the time.
  3926.  
  3927. \ddanger But it isn't ideal, because then the parser will think
  3928. \begintt
  3929. > drop crowns
  3930. \endtt
  3931. refers to a single object, and won't deduce that the player wants to pick
  3932. up all the sensibly available crowns.
  3933. So the complicated (but better way) is to make
  3934. the |parse_name| routine tell the parser that yes, there was a match, but
  3935. that it was a plural.  The way to do this is to set |parser_action| to
  3936. |##PluralFound| (another fake action).  So, for example:
  3937. \beginstt
  3938. Class  crown_class
  3939.   with parse_name
  3940.        [ i j;
  3941.          for (::)
  3942.          {   j=NextWord();
  3943.              if (j=='crown' or j==self.name) i++;
  3944.              else
  3945.              {   if (j=='crowns')
  3946.                  {   parser_action=##PluralFound; i++; }
  3947.                  else return i;
  3948.              }
  3949.        ];
  3950. \endtt
  3951.  
  3952. \exercise  Write a `cherub' class so that if the player tries to call them
  3953. ``cherubs", a message like ``I'll let this go by for now, but the plural of
  3954. cherub is cherubim" appears.^^{cherubim}
  3955.  
  3956. \answer {\beginlines
  3957. |Global c_warned = 0;|
  3958. |Class  cherub_class|
  3959. |  with parse_name|
  3960. |       [ i j flag;|
  3961. |         for (flag=1:flag==1:flag=0)|
  3962. |         {   j=NextWord();|
  3963. |             if (j=='cherub' or j==self.name) flag=1;|
  3964. |             if (j=='cherubs' && c_warned==0)|
  3965. |             {   c_warned=1;|
  3966. |                 parser_action=##PluralFound; flag=1;|
  3967. | print "(I'll let this go once, but the plural of cherub is cherubim.)^";|
  3968. |             }|
  3969. |             if (j=='cherubim')|
  3970. |             {   parser_action=##PluralFound; flag=1; }|
  3971. |             i++;|
  3972. |         }|
  3973. |         return i-1;|
  3974. |       ];|
  3975. \endlines
  3976. Then again, Shakespeare even writes ``cherubins'' in {\sl Twelfth Night},
  3977. so who are we to censure?^^{cherubim}^^{William Shakespeare}}
  3978.  
  3979.  
  3980. \section{21}{Miscellaneous constants and scoring}
  3981.  
  3982. Some game rules can be altered by defining `constants' at the start of
  3983. the program, before the library files are included.  Two constants
  3984. it {\it must} provide are the strings |Story| and |Headline|:
  3985. \beginstt
  3986. Constant Story "ZORK II";
  3987. Constant Headline "^An Interactive Plagiarism^\
  3988.              Copyright (c) 1993 by Ivan O. Ideas.^";
  3989. \endtt^^{plagiarism}^^{Ivan O. Ideas}
  3990. All the rest are optional.
  3991.  
  3992. \medskip 
  3993. The library won't allow the player to carry an indefinite number of
  3994. objects: the limit allowed is the constant |MAX_CARRIED|, which you
  3995. may define if you wish.  If you don't define it, it's 100, which
  3996. roughly removes the rule.  (In fact you can change this `live',
  3997. in that it is actually |player.capacity| which is consulted; the
  3998. only use of |MAX_CARRIED| is to set this up to an initial
  3999. value.)^^|MAX CARRIED|
  4000.  
  4001. If you define |SACK_OBJECT| to be some container, then the player will
  4002. automatically put old, least-used objects away in it as the game
  4003. progresses, provided it is being carried.  This is a feature which
  4004. endears the designer greatly to players.^^|SACK OBJECT|
  4005.  
  4006. \medskip
  4007. Another constant is |AMUSING_PROVIDED|.  If you define this, the library
  4008. knows to put an ``amusing" option on the menu after the game is won.
  4009. It will then call |Amusing()| from your code when needed.  You can
  4010. use this to roll closing credits, or tell the player various strange
  4011. things about the game, now that there's no surprise left to spoil.
  4012. ^^|AMUSING PROVIDED|^^{closing credits}
  4013.  
  4014. \medskip
  4015. The other constants you are allowed to define help the score routines
  4016. along.  There are two ^{scoring systems} provided by the library, side by
  4017. side: you can use both or neither.  (You can always do what you like to
  4018. the |score| variable in any case.)  One scores points for getting certain
  4019. items or reaching certain places; the other for completing certain
  4020. actions.  The constants are:
  4021. \smallskip
  4022. \settabs 8 \columns
  4023. \+ &|MAX_SCORE| && The maximum game score (by default 0)\cr
  4024. \+ &|NUMBER_TASKS| && Number of individual ``tasks" to perform (1)\cr
  4025. \+ &|OBJECT_SCORE| && Bonus for first picking up a |scored| object (4)\cr
  4026. \+ &|ROOM_SCORE| && Bonus for first entering a |scored| room (5)\cr
  4027. \smallskip
  4028. \noindent and then the individual tasks have scores, as follows:
  4029. \begintt
  4030. Global task_scores initial t1 t2 ... tn;
  4031. \endtt^^|task scores|^^|MAX SCORES|^^|NUMBER TASKS|^^|OBJECT SCORE|^^|ROOM SCORE|
  4032. Within your code, when a player achieves something, call ^|Achieved(task)|
  4033. to mark that the task has been completed.  It will only award points if
  4034. this task has not been completed before.
  4035.  
  4036. There do not have to be any ``tasks": there's no need to use the scoring
  4037. system provided.  Tasks (and the verb ``full" for full score) will only
  4038. work at all if you define the constant |TASKS_PROVIDED|.^^|TASKS PROVIDED|
  4039.  
  4040. A routine called ^|PrintRank|, which you can provide if you want, gets the
  4041. chance to print something additional to the score, such as rankings.  For
  4042. instance:
  4043. \beginstt
  4044. [ PrintRank;
  4045.   print ", earning you the rank of ";
  4046.   if (score >= 348) "Grandmaster Adventurer!";
  4047.   if (score >= 330) "Master, first class.";
  4048.   if (score >= 300) "Master, second class.";
  4049.   if (score >= 200) "Junior Master.";
  4050.   if (score >= 130) "Seasoned Adventurer.";
  4051.   if (score >= 100) "Experienced Adventurer.";
  4052.   if (score >= 35) "Adventurer.";
  4053.   if (score >= 10) "Novice.";
  4054.   "Amateur.";
  4055. ];
  4056. \endtt
  4057.  
  4058. |PrintTaskName| prints the name of a game task (such as ``driving the car").
  4059. Of course, this is only ever called in a game with |TASKS_PROVIDED| defined.
  4060. For instance,
  4061. \beginstt
  4062. [ PrintTaskName ach;
  4063.   if (ach==0) "eating a sweet";
  4064.   if (ach==1) "driving the car";
  4065.   if (ach==2) "shutting out the draught";
  4066.   if (ach==3) "building a tower of four";
  4067.   if (ach==4) "seeing which way the mantelpiece leans";
  4068. ];
  4069. \endtt
  4070.  
  4071. \medskip
  4072.  
  4073. Normally, an Inform game will print messages like
  4074. \begindisplay
  4075. [Your score has gone up by three points.]
  4076. \enddisplay^^{score notification}
  4077. when the score changes (by whatever means).  The player can turn this on and
  4078. off with the ^{``notify'' verb}; by default it is on.  You can alter the flag
  4079. |notify_mode| yourself to control this.^^|notify mode|
  4080. \bigskip
  4081.  
  4082. \medskip
  4083. Sometimes you want to ask the player a yes/no question.  If so, call
  4084. ^|YesOrNo()|, a library routine: it returns true/false accordingly (and
  4085. doesn't print any question, which is up to you).  This saves a lot of
  4086. bother programming the parser.^^{questions (yes or no)}
  4087.  
  4088. \ddanger Occasionally you need to rewrite one of the library routines.
  4089. But the danger of doing so is that it is then necessary to keep a copy
  4090. of the library for every game, which is clearly unsatisfactory.  So:
  4091. for example, if the directive
  4092. \beginstt
  4093. REPLACE BurnSub;
  4094. \endtt^^|Replace|
  4095. is placed in your file {\it before the library files are included},
  4096. Inform ignores the definition of |BurnSub| in the library files.
  4097. (You then have to define a routine called |BurnSub| yourself, or Inform
  4098. will complain that the program refers to a routine which isn't there.)
  4099. And this is the ^{very last resort}, and so the end of the manual proper.
  4100.  
  4101.  
  4102. \section{22}{Debugging verbs and tracing}
  4103.  
  4104. \quote
  4105. If builders built buildings the way programmers write programs,
  4106. the first ^{woodpecker} that came along would destroy civilisation.
  4107. \quoteby{old computing adage}
  4108.  
  4109. The two problems with debugging a game are working out exactly what it's
  4110. doing, and making things happen which wouldn't normally be allowed (such
  4111. as giving yourself the trident now rather than playing for two hours to
  4112. find it).
  4113.  
  4114. Inform provides a small suite of ^{debugging verbs} to help with this, but
  4115. only if the game defines the constant ^|DEBUG| before including the library
  4116. files.  (Just in case you forget to take this out again, the letter D
  4117. appears in the game banner to indicate this.)
  4118.  
  4119. You then get the following verbs, which can be used at any time in play:
  4120. \begintt
  4121. purloin <anything>
  4122. abstract <anything> to <anything>
  4123. tree       tree <thing>
  4124. goto <number>
  4125. actions    actions on    actions off
  4126. routines   routines on   routines off
  4127. timers     timers on     timers off
  4128. trace      trace on      trace off    trace <1 to 5>
  4129. \endtt
  4130. You can ``purloin" any item or items in your game at any time, wherever
  4131. you are.  You can likewise ``abstract" any item to any other item (meaning:
  4132. move it to the other item).  To get a listing of the objects in the game
  4133. and how they contain each other, use ``tree", and to see the possessions of
  4134. one of them alone, use ``tree \<that>".  Finally, you can go to any object:
  4135. but since rooms don't have names understood by the parser, you have to give
  4136. the object number of the place you want to go to.  (The ``tree" listing will
  4137. tell you these numbers.)
  4138. ^^{``actions'' verb}^^{``tree'' verb}^^{``purloin'' verb}^^{``routines'' verb}
  4139. ^^{``trace'' verb}^^{``abstract'' verb}^^{``goto'' verb}
  4140. Turning on ``actions" gives a trace of all the actions which take place in
  4141. the game (the parser's, the library's or yours); turning on ``routines"
  4142. traces every object routine (such as |before| or |life|) that is ever
  4143. called, except for |short_name| (as this would look chaotic, especially on
  4144. the status line).  Turning on ``timers'' shows the state of all active timers
  4145. and daemons each turn.^^{``timers'' verb}
  4146. ^^{tracing routines, actions, daemons and timers}
  4147.  
  4148. \medskip
  4149. ^{Infix}, Dilip Sequeira's ^{source-level debugger} for Inform, is currently
  4150. in an advanced state of preparation: it is an enhanced form of Mark Howell's
  4151. ^{Zip} interpreter providing for breakpoints, tracing and so forth.  It
  4152. should fairly soon be publically archived with the rest of the Inform project.
  4153.  
  4154. \danger For Infix's benefit, Inform (if compiling with the option set) produces
  4155. a file of ``debugging information'' (cross-references of the game file with
  4156. the source code), and anyone interested in writing an Inform utility program
  4157. may want to know the format of this file: see the short C program ^{Infact}
  4158. which prints out the debugging information file in English.
  4159.  
  4160. On most interpreters, though, ^{run-time crashes} are mysterious (because they
  4161. were written on the assumption that all existing Infocom game files were free
  4162. from error).  ^{Zip} is rather more generous and will usually tell you why and
  4163. where the problem is; given a game file address you can work back to the
  4164. problem point in the source either with Mark Howell's ^{txd (disassembler)}
  4165. or by running Inform with the assembler trace option on.
  4166.  
  4167. Here are all the ways I know to crash an interpreter at run-time (with
  4168. high-level Inform code, that is; if you insist on using
  4169. assembly language or the ^|indirect| function you're raising the stakes),
  4170. arranged in decreasing order of likelihood:
  4171. ^^{crashing the interpreter}
  4172. \item{$\bullet$} Writing to a property of an object which it hasn't got;
  4173. \item{$\bullet$} Dividing by zero, possibly by calling |random(0)|;^^|random|
  4174. \item{$\bullet$} Giving a string or numerical value for a property which can
  4175. only legally hold a routine, such as |before|, |after| or |life|;
  4176. \item{$\bullet$} Applying ^|parent|, ^|child| or ^|children| to the ^|nothing|
  4177. object;
  4178. \item{$\bullet$} Using ^|print object| on the |nothing| object, or for some
  4179. object which doesn't exist (always use the routines |DefArt|, |CDefArt| or
  4180. |PrintShortName| as appropriate, which are safeguarded and anyway
  4181. implement higher-level features);
  4182. \item{$\bullet$} Using |print_addr| or |print_paddr| to print from an address
  4183. outside the memory map of the game file, or an address at which no string
  4184. is present (this will result in random text appearing, possibly including
  4185. unprintable characters, which may conceivably crash your terminal);
  4186. ^^|print addr|^^|print paddr|
  4187. \item{$\bullet$} Setting the |location| variable to zero, or some non-existent
  4188. object, since the interpreter prints the name of this object on the
  4189. ^{status line};
  4190. in any case it is safer to use ^|PlayerTo| than to meddle directly with this;
  4191. \item{$\bullet$} Running out of stack space in a recursive loop (though this
  4192. has never actually happened to anyone I know of).
  4193.  
  4194. \danger^^{parser tracing and levels}
  4195. There are times when it's hard to work out what the parser is up to and why
  4196. (actually, most times are like this).  The parser is written in levels, the
  4197. lower levels of which are murky indeed.  Most of the interesting things
  4198. happen in the middle levels, and these are the ones for which tracing is
  4199. available.  The levels which can be traced are:
  4200. \smallskip\ninepoint
  4201. \settabs 8\columns
  4202. \+&  Level 1  &&   Grammar lines\cr
  4203. \+&  Level 2  &&   Individual tokens\cr
  4204. \+&  Level 3  &&   Object list parsing\cr
  4205. \+&  Level 4  &&   Resolving ambiguities and making choices of object(s)\cr
  4206. \+&  Level 5  &&   Comparing text against an individual object\cr
  4207. \smallskip\noindent
  4208. ``trace" or ``trace on" give only level 1 tracing.  Be warned: ``trace five"
  4209. can produce reams of text when you try anything at all complicated: but you
  4210. do sometimes want to see it, to get a list of exactly everything that is in
  4211. scope and when.  There are two levels lower than that but they're too busy
  4212. doing dull spade-work to waste time on looking at |parser_trace|.  (There's
  4213. also a level 0, but it consists mostly of making arrangements for level 1,
  4214. and isn't very interesting.)^^{tracing the parser}\tenpoint
  4215.  
  4216. \ddanger
  4217. Finally, though this is a drastic measure, you can always compile your game
  4218. |-g| (^{`debugging code'}) which gives a listing of every routine ever
  4219. called and their parameters.  This produces an enormous mel\'ee of output. 
  4220. (In Inform 5.3, though not earlier versions, you can declare a routine with
  4221. an asterisk ^|*| as its first local variable, which produces such tracing only
  4222. for that one routine.)^^{tracing a routine}^^{routine tracing}
  4223.  
  4224.  
  4225. \section{23}{Limitations on the run-time format}
  4226.  
  4227. \poem
  4228. How wide the limits stand
  4229. Between a splendid and an happy land.
  4230. \poemby{^{Oliver Goldsmith} (1728-1774)}{The Deserted Village}
  4231.  
  4232. ^^{limitations}
  4233. The Infocom ^{run-time format} is well-designed, and has three major
  4234. advantages: it is compact, widely portable and can be quickly executed.
  4235. Nevertheless, like any rigidly defined
  4236. format (which it clearly must be), it imposes limitations.  These are not
  4237. by any means pressing.  Inform itself has a flexible enough memory-management
  4238. system not to impose artificial limits on numbers of objects and the like.
  4239.  
  4240. There are two sizes of game available: Standard (or version 3) and Advanced
  4241. (or version 5).  Always use the latter if you can; it is very much to be
  4242. preferred.  (There are very slight risks associated with exotic
  4243. assembly-language coding in Advanced games: but unless you deviate far
  4244. from normal Inform practice, and code on a very low level, these will never
  4245. trouble you.)  There are still 8-bit computers in use which are too small
  4246. for ^{Advanced games}, but most people should have no problem.^^{Standard games}
  4247. \medskip
  4248.  
  4249. {\it Memory.}\quad The total size of a Standard game is at most 128K; of an
  4250. Advanced game, 256K.  Because games are encoded in a very compressed form,
  4251. and because the centralised library of Inform makes the compiler fairly
  4252. efficient in terms of not duplicating code, even 128K allows for a game
  4253. at least half as large again as a typical old-style Infocom game.  No game
  4254. yet written under Inform has reached the 256K mark, not even the final
  4255. version of `Curses' (at 224K, already substantially bigger and denser than
  4256. any Infocom game).^^{memory size}
  4257. \medskip
  4258.  
  4259. {\it Vocabulary.}\quad There is no theoretical limit, and vocabularies
  4260. in excess of 2000 are quite sensibly possible.  (A typical large game will
  4261. muster 1000.)^^{vocabulary size}
  4262. \medskip
  4263.  
  4264. {\it Dictionary resolution.}\quad In Standard games, dictionary words are
  4265. truncated to their first 6 letters, which can be a nuisance; in Advanced,
  4266. 9 letters, which never is.^^{dictionary resolution}
  4267. \medskip
  4268.  
  4269. {\it Attributes, properties, names.}\quad Standard games only provide
  4270. 32 attributes, 30 properties and at most 8 bytes of data per property:
  4271. the library consumes most of this ration, and the 8 bytes restriction
  4272. means that an object can only have four words in its |name|.  This is
  4273. perfectly manageable, if unsatisfactory.  Advanced games, which provide 48
  4274. attributes, 62 properties and 64 bytes of data (hence 32 names), effectively
  4275. make none of these restrictions serious.
  4276. \medskip
  4277.  
  4278. {\it Special effects.}\quad Standard games cannot have special effects such
  4279. as bold face and underlining.  (See the next two sections.)
  4280. \medskip
  4281.  
  4282. {\it Objects.}\quad Standard games can have at most 255 objects, enough for
  4283. a large Infocom-size game but not much more.  Advanced games have no such
  4284. restriction, the number being in principle unlimited.  Objects cannot
  4285. dynamically be created or destroyed, but this is imitated easily enough.
  4286. \medskip
  4287.  
  4288. {\it Global variables.}\quad There can only be 240 of these, and the Inform
  4289. compiler uses 5 as scratch space, while the library uses slightly over 100;
  4290. but since a typical game uses only a dozen of its own, code being almost
  4291. always object-oriented, the restriction is never even nearly felt.  (Recall
  4292. that arrays take only one global each.)
  4293. \medskip
  4294.  
  4295. {\it ``Undo''.}\quad Standard games do not provide an ^{``undo'' verb},
  4296. but Advanced ones (or rather, the Inform library when compiled on such)
  4297. do.
  4298.  
  4299. \bigskip
  4300.  
  4301. \danger There is a yet larger Infocom format, ^{version 6}, which lifts even the mild
  4302. restrictions of version 5 games, with memory maps of up to
  4303. 600K or so: version 6 has only recently been fully deciphered, but Inform is
  4304. already capable of producing such files, and Mark Howell's ``Zip''
  4305. interpreter is (at time of writing) making good progress in running them.
  4306. A 600K Inform game would be gargantuan: by the time one comes along, there
  4307. should be no problem in running it.
  4308.  
  4309. \ddanger  Having said all this, if memory does become short, there is a
  4310. standard mechanism for saving about 8-10\% of the memory.  Inform does
  4311. not usually trouble to, since there's very seldom the need, and it makes
  4312. the compiler run about 10\% slower.  What you need to do is define
  4313. ^{abbreviations}.  For instance, the directive
  4314. \beginstt
  4315. Abbreviate " the ";
  4316. \endtt
  4317. (placed before any text appears) will cause the string `` the '' to be
  4318. internally stored as a single `letter', saving memory every time it occurs
  4319. (about 2500 times in `Curses', for instance).  You can have up to 64
  4320. abbreviations.  A good list of abbreviations can be found in the
  4321. {\sl Technical Manual}: basically, avoid proper nouns and instead pick on short
  4322. combinations of a space and common two- or three-letter blocks.  You can
  4323. even get Inform to work out by itself what a good stock of abbreviations
  4324. would be: but be warned, this makes the compiler run about 29000\% slower.
  4325.  
  4326.  
  4327. \section{24}{A very few, not very special effects}
  4328.  
  4329. \quote
  4330. Yes, all right, I won't do the menu... I don't think you realise
  4331. how long it takes to do the menu, but no, it doesn't matter, I'll
  4332. hang the picture now.  If the menus are late for lunch it doesn't
  4333. matter, the guests can all come and look at the picture till they
  4334. are ready, right?
  4335. \poemby{^{John Cleese} and ^{Connie Booth}}{Fawlty Towers}
  4336.  
  4337. As the previous section suggested, some ^{special effects} are not to be
  4338. encouraged: they reduce portability a little, and anyway Inform is for
  4339. text games.
  4340.  
  4341. The ^{status line} is perhaps the most distinctive feature of Infocom games in
  4342. play.  This is the (usually highlighted) bar across the top of the screen. 
  4343. Usually, the game automatically prints the current game location, and either
  4344. the time or the score and number of turns taken.  It has the score/turns
  4345. format unless the directive
  4346. \begintt
  4347. Statusline time;
  4348. \endtt
  4349. is present, in which case it shows the game's 24-hour clock.
  4350.  
  4351. \ddanger If you {\it really} want to change this, then |Replace| the parser's
  4352. private |DrawStatusLine| routine.  But be sure to test the result on more
  4353. than one interpreter, in case you've made a mistake which doesn't show up on
  4354. one quirky implementation.  (In any case, you can only change it at all on
  4355. Advanced games.)
  4356.  
  4357. \ddangerexercise  Alter the ^{`Advent'} example game to display the number
  4358. of treasures found instead of the score and turns on the status line.
  4359.  
  4360. \answer{First put the directive |Replace DrawStatusLine;| before including
  4361. the library.  Then add the following routine anywhere after |treasures_found|,
  4362. an `Advent' variable, is defined:
  4363. \beginlines
  4364. |[ DrawStatusLine;|
  4365. |   @split_window 1; @set_window 1; @set_cursor 1 1; style reverse;|
  4366. |   spaces (0->33)-1;|
  4367. |   @set_cursor 1 2;  PrintShortName(location);|
  4368. |   if (treasures_found > 0)|
  4369. |   {   @set_cursor 1 50; print "Treasure: ", treasures_found;|
  4370. |   }|
  4371. |   @set_cursor 1 1; style roman; @set_window 0;|
  4372. |];|
  4373. \endlines}
  4374.  
  4375. About ^{character graphic} ^{drawings}: on some machines, text will by default
  4376. be displayed in a ^{proportional font} (i.e. one in which the width of a letter
  4377. depends on what it is, so that for example an `i' will be narrower than an
  4378. `m').  If you want to display a diagram made up of letters, such as a map,
  4379. you will have to turn this off, for which the ^|font| command is provided.
  4380. Write |font off| before printing character graphics, and remember to
  4381. write |font on| again afterwards.
  4382.  
  4383. \warning Don't turn the |font| on and off in the middle of a line; this
  4384. doesn't look right on some machines.
  4385.  
  4386. A distinctive feature of later Infocom games was their use of ^{epigrams}.
  4387. Inform can do this, too, but only for Advanced games.  The
  4388. assembly language required is easy but a nuisance, so there is a command
  4389. to do it, ^|box|.  For example,
  4390. \beginstt
  4391. box "Beware of the Dog";
  4392. \endtt
  4393. or
  4394. \beginstt
  4395. box "I might repeat to myself, slowly and soothingly,"
  4396.     "a list of quotations beautiful from minds profound;"
  4397.     "if I can remember any of the damn things."
  4398.     ""
  4399.     "-- Dorothy Parker";
  4400. \endtt^^{Dorothy Parker}^^{quotations beautiful}
  4401. Note that a string of lines is given (without intervening commas) and
  4402. that a blank line is given by a null string.  Remember that the text
  4403. cannot be too wide or it will look awful on a small screen.
  4404.  
  4405. The author takes the view that this device is amusing for irrelevant
  4406. quotations but irritating when it conveys vital information (such as,
  4407. ``Beware of the Dog", for instance).  Also, some people might be running
  4408. your game on a laptop with a vertically challenged screen, so it is
  4409. polite to provide a ^{``quotes off'' verb}.
  4410. \medskip
  4411.  
  4412. Sometimes one would like to provide a ^{menu of text options} (for instance,
  4413. when producing instructions which have several topics, or when giving
  4414. ^{clues}).  This can be done with the ^|DoMenu| routine, which imitates
  4415. the traditional ^{``Invisiclues''} style.  However, it only looks good
  4416. for Advanced games; for Standard games, it's simply textual.  (In an
  4417. Advanced game, by setting |pretty_flag=0| you can get this simple text
  4418. version instead; which is a good idea for machines with very small
  4419. screens.)
  4420.  
  4421. Here is a typical call to |DoMenu|:
  4422. \beginstt
  4423. DoMenu("There is information provided on the following:^\
  4424.         ^     Instructions for playing\
  4425.         ^     The history of this game\
  4426.         ^     Credits^",
  4427.         #r$HelpMenu, #r$HelpInfo);
  4428. \endtt
  4429. Note the layout, and especially the carriage returns.  The second and
  4430. third arguments are themselves routines: the notation |#r$|, seldom
  4431. seen in high-level Inform, allows routine names to become ordinary
  4432. numerical values.  The first routine, in this case called |HelpMenu|,
  4433. is supposed to look at the variable |menu_item|.  In the case when this
  4434. is zero, it should return the number of entries in the menu (3 in the
  4435. example).  In any case it should set |item_name| to the title for the
  4436. page of information for that item; and |item_width| to half its length
  4437. in characters (this is used to centre titles on the screen: it is
  4438. unfortunately tricky for the game to compute the length of a static
  4439. string, so you have to tell it).
  4440. In the case of item 0, the title should be that for the whole menu.
  4441.  
  4442. The second routine, |HelpInfo| above, should simply look at |menu_item|
  4443. (1 to 3 above) and print the text for that selection.  After this returns,
  4444. normally the game prints ``Press [Space] to return to menu'' but if
  4445. the value 2 is returned it doesn't wait.
  4446.  
  4447. Menu items can safely launch whole new menus, and it is easy to make
  4448. a tree of these (which will be needed when it comes to providing hints
  4449. across any size of game).
  4450.  
  4451. \exercise Code an ``Invisiclues''-style sequence of hints for a puzzle,
  4452. revealed one at a time, as a menu item.
  4453.  
  4454. \answer{Note the magic line of assembly code here, which only works for
  4455. Advanced games:
  4456. \beginlines^^{``Invisiclues''}
  4457. |[ GiveHint hint keypress;|
  4458. |  print_paddr hint; new_line; new_line;|
  4459. |  @read_char 1 0 0 keypress;|
  4460. |  if (keypress == 'H' or 'h') rfalse;|
  4461. |  rtrue;|
  4462. |];|
  4463. \endlines
  4464. And a typical menu item using it:
  4465. \beginlines
  4466. | if (menu_item==1)|
  4467. | {   print "(Press ENTER to return to menu, or H for another hint.)^^";|
  4468. |     if (GiveHint("(1/3)  What kind of bird is it, exactly?")==1) return 2;|
  4469. |     if (GiveHint("(2/3)  Magpies are attracted by shiny items.")==1) return 2;|
  4470. |     "(3/3)  Wave at the magpie with the kitchen foil.";|
  4471. | }|
  4472. \endlines}
  4473.  
  4474. \bigskip
  4475. Finally, though it should only be used sparingly (and again is restricted
  4476. to ^{Advanced games}), one can change the ^{text style}.  The command for
  4477. this is ^|style| and its effects are loosely modelled on the ^{VT100}
  4478. (design of terminal).  The style can be |style roman|, |style bold|,
  4479. |style reverse| or |style underline|.  Again, remember that poor terminals
  4480. may not be able to display these, so you shouldn't hide crucial information
  4481. in them.^^{boldface}^^{roman text}^^{reverse video}^^{underlining}
  4482.  
  4483.  
  4484. \section{25}{Dirty tricks}
  4485.  
  4486.  
  4487. \ddanger The dirtiest tricks of all are those which bypass Inform's higher
  4488. levels and program the Z-machine directly.  There is an element of danger in
  4489. ^{assembly language} programming, in that some combinations of unusual opcodes
  4490. can look ugly on some incomplete or wrongly-written ^{interpreters}: so if you're
  4491. doing anything complicated, test it as widely as possible.
  4492. Note that none of the interesting effects work at all on ^{Standard games},
  4493. only ^{Advanced games}.^^{dirty tricks}
  4494.  
  4495. \ninepoint
  4496.  
  4497. The best-researched and most reliable interpreter available by far is Mark
  4498. Howell's ^{Zip}; as it's also the fastest, it will hopefully `take over' entirely.
  4499. Next comes the ^{InfoTaskForce}, which is thorough and should give no serious
  4500. trouble, but was written when the format was a little less well understood,
  4501. and so (in some ports) gets some (rare) screen effects wrong.  (It also lacks
  4502. an ``undo'' feature, so the ^{``undo'' verb} automatically provided by the library
  4503. routines won't work under ITF.)  The other two publically-available
  4504. interpreters are ^{pinfocom} and ^{zterp}, but these are unable to run Advanced
  4505. games.  In the last resort, sometimes it's possible to use one of Infocom's
  4506. own supplied interpreters with a different game from that it came with; but only
  4507. sometimes, as they may have inconvenient filenames `wired into them'.  The
  4508. author recommends that anyone using assembly-language features get hold of
  4509. both ITF and Zip, and test on both.
  4510.  
  4511. This all sounds rather unportable, though actually the core described below
  4512. is pretty reliable.  But remember that the unportability does have some genuine
  4513. cause.  Your game may be running on a screen which is anything from a 64 by 9
  4514. pocket organiser up to a 132 by 48 X-window.
  4515.  
  4516. Anyone wanting to really push the outer limits (say, by implementing
  4517. ^{Space Invaders} or ^{NetHack}) will need to refer to {\sl The Specification
  4518. of the Z-Machine}, which also documents Inform assembly language format.
  4519. \bigskip
  4520.  
  4521. Screen tricks are the commonest.  An upper-level screen (which usually holds
  4522. the status line) can be split off from the main screen:^^{screen tricks}
  4523. \beginstt
  4524. split_window n;
  4525. \endtt^^|split window|
  4526. creates one which is $n$ lines tall.  (This doesn't change the display, and
  4527. it can be resized at any time: but it needs to be tall enough to include all
  4528. the lines you want to write to, as otherwise the interpreter may flounder:
  4529. some will scroll the upper window, others won't.)  The
  4530. main screen is numbered 0, and the upper one 1; text output is switched between
  4531. them by
  4532. \beginstt
  4533. set_window n;
  4534. \endtt^^|set window|
  4535. The lower window is just a text stream whose cursor position cannot be set: on
  4536. the other hand, when it is returned to, the cursor will be where it was before
  4537. it was left.  Within the upper window, the cursor can be moved by
  4538. \beginstt
  4539. set_cursor line column;
  4540. \endtt^^|set cursor|
  4541. where $(1,1)$ is the top left character.  Printing on the upper window
  4542. overlies printing on the lower, is always done in a fixed-space font
  4543. and does not appear in a printed ^{transcript} of the game.
  4544. However, before printing to the upper window, it is essential to
  4545. change the printing format - that is, the |buffer_mode| opcode.  Before
  4546. printing, execute
  4547. \beginstt
  4548. buffer_mode 0;
  4549. \endtt^^|buffer mode|
  4550. and when returning to the normal screen,
  4551. \beginstt
  4552. buffer_mode 1;
  4553. \endtt
  4554. Otherwise, dodgy interpreters (like ITF) may continue trying to split
  4555. lines at word breaks, and make a horrid mess.
  4556. \medskip
  4557.  
  4558. A convenient way to clear the screen is
  4559. \beginstt
  4560. erase_window $ffff;
  4561. \endtt^^{clearing the screen}^^|erase window|
  4562. but don't chance this in reverse video mode!  (And don't assume that |erase_window|
  4563. can erase individual windows - it should, but may not on bad interpreters.)
  4564. \medskip
  4565.  
  4566. Players can be gratuitously annoyed (on most machines, anyway) by the |beep| opcode.
  4567. This is the only remotely portable ^{sound effect}.^^|beep|
  4568. \medskip
  4569.  
  4570. The ^{keyboard} can be read in remarkably flexible ways, using the |aread| and
  4571. |read_char| opcodes.^^|read char|^^|aread|
  4572. \beginstt
  4573. aread text parse time function;
  4574. \endtt
  4575. will read from the keyboard, putting text into the |text| buffer, tokenising
  4576. it onto the end of the |parse| buffer (unless this is zero), and calling
  4577. \beginstt
  4578. function(time);
  4579. \endtt
  4580. every |time| seconds that the user is thinking: the process ends if ever this
  4581. function returns true.  Thus (by |Replace|ing the |Keyboard| routine in the
  4582. library files) you could, say, move around all the characters every ten seconds
  4583. of ^{real time}.^^{timed input}
  4584. \beginstt
  4585. read_char 1 time function <result>;
  4586. \endtt
  4587. where |<result>| is a variable, will store in that variable the ASCII value
  4588. of a single keypress.  Once again, the |function| is called every |time| seconds
  4589. and may stop this process early.  Function keys return special values from 129
  4590. onwards, in the order: cursor up, down, left, right, function key f1, ..., f12,
  4591. keypad digit 0, ..., 9.^^{function keys}^^{cursor keys}
  4592. \medskip
  4593.  
  4594. Leafing through the dictionary of opcodes will reveal a few other interesting
  4595. features.  It's possible to change the input and ^{output streams} which, although
  4596. only Zip gets this right, may be convenient for debugging purposes (creating
  4597. scripts of all typed commands, for example).  Finally, there are opcodes which
  4598. tokenise (that is, simply compare dictionary entries against) arbitrary
  4599. strings from arbitrary dictionaries, and which translate small doses of ASCII
  4600. to internal Z-machine string format.  Actually, one can avoid the need for this
  4601. in many cases, by programming the parser correctly: see, for instance,
  4602. the `Balances' game which manages without these features.
  4603. \tenpoint
  4604. \vfill\eject
  4605. % ---------------------------------------------------------------------------
  4606. %   Appendices to the Inform Designer's Manual
  4607. % ---------------------------------------------------------------------------
  4608.  
  4609. \section{A1}{The Inform language}
  4610.  
  4611. This is going to be a long appendix, full of lists and tables: but it has
  4612. to appear somewhere, if only for reference.  (Some technical commands
  4613. for internal use only are skipped over: see the {\sl Technical Manual} for
  4614. details of these.)
  4615. \ninepoint
  4616.  
  4617. \subsection{File format}
  4618. When Inform reads in a file, it treats a few characters in special ways.
  4619. The character |!| means the rest of the line (up to the next new-line) is
  4620. a comment, and Inform throws it away.  Tab characters are treated as
  4621. spaces.  Backslashes |\| fold strings together, so that the new-line and
  4622. all subsequent spaces are ignored.  New-lines have no significance;
  4623. statements (and directives) are separated by semicolons |;|.^^{comments}
  4624. ^^{backslash}^^{file format}
  4625.  
  4626. \subsection{Directives}
  4627. These are commands directly to the Inform compiler, like |Object|.  They
  4628. can, but need not, be prefaced by a hash character, |#|.  The directives
  4629. which Inform understands are:^^{directives}^^{hash character}
  4630. \smallskip{\ninepoint
  4631. \settabs 8 \columns
  4632. \+ &|Abbreviate| \<string>&&&  Declare an abbreviation\cr
  4633. \+ &|Attribute| \<name>&&&  Make a new attribute\cr
  4634. \+ &|Class| ...&&&  Define a new class\cr
  4635. \+ &|Constant| \<name> \<value> &&&  Define a named constant\cr
  4636. \+ &|End| &&&  End compilation here\cr
  4637. \+ &|Endif| &&&  End of conditional compilation\cr
  4638. \+ &|Extend| ... &&& Extend the grammar for an existing verb\cr
  4639. \+ &|Fake_action| \<name> &&&  Make a new ``fake action''\cr
  4640. \+ &|Global| \<name> ... &&&  Declare a global variable\cr
  4641. \+ &|Ifdef| \<name> &&& Compile only if constant is defined\cr
  4642. \+ &|Ifndef| \<name> &&& Compile only if constant is undefined\cr
  4643. \+ &|Ifnot| &&& Compile only if previous |If...| failed\cr
  4644. \+ &|Ifv3| &&& Compile only for Standard games\cr
  4645. \+ &|Ifv5| &&& Compile only for Advanced games\cr
  4646. \+ &|Include| \<filename> &&&  Include that file here\cr
  4647. \+ &|Nearby| &&& Make an object inside the last |Object|\cr
  4648. \+ &|Object| &&& Make an object\cr
  4649. \+ &|Property| \<name> ... &&& Make a new property\cr
  4650. \+ &|Replace| \<routine> &&& Don't compile this library routine\cr
  4651. \+ &|Release| \<number> &&& Set the game's Release Number\cr
  4652. \+ &|Serial| \<string> &&& Set the game's Serial Number\cr
  4653. \+ &|Statusline| ... &&& Make the status line show score or time\cr
  4654. \+ &|Switches| \<switches> &&& Set default compilation switches\cr
  4655. \+ &|Verb| ... &&& Declare the grammar for a new verb\cr
  4656. \smallskip}\noindent
  4657.  
  4658. The ^{release number} of a game (by default 1) is generally an edition
  4659. number; the ^{serial number} is the compilation date in the form
  4660. 940924, that is, yymmdd.  Inform sets this automatically on machines
  4661. where the date is accessible, so the |Serial| directive is provided
  4662. only for use on machines without such an internal clock.
  4663.  
  4664. \danger Conditional compilation allows code for routines which need only
  4665. exist in some ``versions" of your games.  For instance,
  4666. ^^{conditional compilation}
  4667. \begintt
  4668.   print "Welcome to the ";
  4669.   #IFV3; print "Standard"; #IFNOT; print "Advanced"; #ENDIF;
  4670.   print " version of Zork LVI.";
  4671. \endtt
  4672. (The |#IFNOT| clause is optional.)  Note the trailing semicolon: Inform
  4673. is not C!  Such clauses may be nested up to 32 deep, and may contain whole
  4674. routines.  They may not, however, conditionally give {\it part} of a
  4675. statement.  Thus, for instance,
  4676. \begintt
  4677.   print #IFV3; "Standard"; #IFNOT; "Advanced"; #ENDIF;
  4678. \endtt
  4679. is {\sl not} legal.
  4680.  
  4681. \ddanger The following directives are recondite and not for public use:
  4682. \begintt
  4683. Default Dictionary Listsymbols Listdict Listverbs Lowstring Stub System_file
  4684. Trace Btrace Etrace Ltrace Notrace Nobtrace Noetrace Noltrace
  4685. \endtt
  4686.  
  4687. \subsection{Variables and arrays}
  4688. There are two kinds of variable, global and local (plus one special one).
  4689. Variables are all two-byte integers, which are treated as signed when it
  4690. makes sense to do so (e.g. in asking whether one is positive or not) but
  4691. not when it doesn't (e.g. when it is used as an address).
  4692. Global variables must be declared before use, by the ^|Global| directive:
  4693. ^^{arrays}^^{variables}
  4694. \begindisplay
  4695. |Global| \<varname> = \<initial-value>\cr
  4696. \phantom{|Global| \<varname>} |data| \<size>\cr
  4697. \phantom{|Global| \<varname>} |string| \<size>\cr
  4698. \phantom{|Global| \<varname>} |initial| \<value-1> ... \<value-$n$>\cr
  4699. \phantom{|Global| \<varname>} |initstr| \<text>\cr
  4700. \enddisplay
  4701. For instance:
  4702. \begintt
  4703. Global turns = 1;
  4704. Global buffer string 120;   ! text buffer holding 120 characters
  4705. Global task_scores initial 4 5 9 1 2 3 0;  ! a 7-byte array
  4706. Global players_name initstr "Graham";  ! an array of 6 chars
  4707. \endtt
  4708. When you declare a variable as an array (by |data|, |string|, ^|initial|
  4709. or ^|initstr|)
  4710. what actually happens is that Inform allocates as much space as you ask
  4711. for, somewhere inside the machine, and stores the address of this array
  4712. in the variable.  You can get at entries of the array by^^|->|^^|-->|
  4713. \begintt
  4714. buffer->entry    buffer-->entry
  4715. \endtt
  4716. which read (or write to) the |entry|-th byte (in the case of |->|) or
  4717. word (for |-->|).  A |data| array is initially full of zeros, while an
  4718. |initial| array contains the given (byte) values, which all have to be
  4719. constants for obvious reasons.  A ^|string| array is a special kind of
  4720. ^|data| array: the first byte contains its length (in bytes), and the
  4721. rest are initially zero.  ^|initstr| is the same but initialised to
  4722. the given string.  The text here is plain ASCII, and is not encrypted
  4723. as constant strings tend to be.  (This string format is used by the
  4724. parser.)
  4725.  
  4726. In addition, a routine can have from none up to 15 ^{local variables}.
  4727.  
  4728. \warning There is also a stack, but it should be tampered with only
  4729. carefully in times of dire need.  Never call a variable ^|sp|, as this is the
  4730. ^{stack pointer}, and if you must use the stack at all, be careful not to
  4731. leave values on it: or your game may crash 1000 turns later, serving you
  4732. right.
  4733.  
  4734. \subsection{Constants}
  4735. Inform ^{constants} can take many forms.  The obvious ones are numbers,
  4736. \begintt
  4737. 123   $ee05   $$11011001
  4738. \endtt
  4739. being examples in decimal, hexadecimal and ^{binary} respectively.  There
  4740. are also
  4741. \smallskip
  4742. \settabs 8 \columns
  4743. \+ &|##Action| &&  (The number of) the given action\cr
  4744. \+ &|"some text"| &&  (The packed address of) the given string\cr
  4745. \+ &|'c'| &&  (The ASCII code for) the given character\cr
  4746. \+ &|'word'| &&  (The byte address of) its dictionary entry\cr
  4747. \smallskip\par\noindent
  4748. There is slight potential for confusion here: |'A'| evaluates to 65,
  4749. but |'an'| to the dictionary address of the word `an'.  Note that
  4750. the construction |'sponge'| actually enters the word `sponge' into
  4751. the dictionary if it wasn't already there.  These are all legal
  4752. constants:
  4753. \begintt
  4754. 31415  -1  $ff  $$1001001  'lantern'  ##Look  'X'
  4755. "an emerald the size of a plover's egg"
  4756. "~Hello,~ said Peter.^~Hello, Peter,~ said Jane.^"
  4757. \endtt^^{Peter and Jane}
  4758.  
  4759. \subsection{Quoted strings}
  4760. Inside the text of a string, the character |^| is replaced by a new-line
  4761. character, and the character |~| by a double-quote mark: these both make
  4762. strings much easier to type.
  4763.  
  4764. Inside a string (under Inform 5.3 or later) ^|@@|\<number> produces the
  4765. character whose ASCII value is $n$, and you can use this to get untypeable
  4766. characters from ^{foreign character sets}.  (Or, for example, a literal
  4767. ^{backslash}, by |@@92|.)
  4768.  
  4769. For the |@| string escape and other obscure constant forms such as
  4770. |#r$|, see the {\sl Technical Manual}.
  4771.  
  4772. \subsection{Routines}
  4773. Routines start with a |[| and end with a |]|.  That is, they open with
  4774. \begindisplay
  4775. |[| \<Routine-name> \<local-var-1> ... \<local-var-$n$>|;|
  4776. \enddisplay
  4777. giving the names of local variables for the routine ($0\leq n\leq 15$).
  4778. The routine ends with just |];|.  (Routines embedded in object definitions
  4779. are the same, except that no routine-name is given, and they may end in
  4780. |],| if the object definition continues.)^^{routines}^^{embedded routines}
  4781.  
  4782. The first few local variables also hold the arguments passed to the
  4783. routine when the function is called.  That is, if you have a routine
  4784. \begintt
  4785.   [ Look from i j; ...some code...; ];
  4786. \endtt
  4787. ^^{function arguments}
  4788. and it is called by |Look(attic);| then the local variable |from| will
  4789. initially have the value |attic|.  The rest all start out at zero.
  4790.  
  4791. From Inform 5.3, if the first variable is given as ^|*| then
  4792. tracing code is compiled to print details each time the routine
  4793. is called.
  4794.  
  4795. Function calls (that is, calls to routines) are legal with between 0
  4796. and 3 arguments, and every routine always returns a value.  If execution
  4797. runs into the |];| at the bottom, that value is `true' (or 1) for an
  4798. ordinary routine, or `false' (or 0) for an embedded one.
  4799.  
  4800. \subsection{Labels}
  4801. ^^{labels}
  4802. In case you want to ^|jump| around inside a routine, you can define labels
  4803. with a statement starting with a full stop, like |.labelname;|.  It is
  4804. legal, though ill-advised, to jump out of one routine and into another.
  4805. Label names are global, so the same label name can't be used in two
  4806. different routines.
  4807.  
  4808. \subsection{Operators}
  4809. Arithmetic (and other) ^{expressions} can contain the following:
  4810. ^^{arithmetic operators}
  4811. \smallskip
  4812. \settabs 8 \columns
  4813. \+ &|+ -| &        plus, minus\cr
  4814. \+ &|* / % & |{\tt\char`\|}
  4815. & times, divide, remainder, bitwise and, bitwise or\cr
  4816. \+ &|-> -->| &     byte array, word array entry\cr
  4817. \+ &|. .& .#| &    property, property address, property length\cr
  4818. \+ &|-| &          unary minus\cr
  4819. \+ &|++ --| &      incrementing and decrementing variables (as in C)\cr
  4820. \smallskip\par\noindent
  4821. The order of precedence is as shown: i.e. those on each line are equally
  4822. potent, more potent than those above but less than those beneath.
  4823. Expressions are not allowed to contain conditions, nor assignments:
  4824. |2+(i=3/j)| is not a legal expression.  Some legal examples:
  4825. \begintt
  4826. 4*(x+3/y)   Fish(x)+Fowl(y)  lamp.time   buffer->5
  4827. \endtt
  4828. Note that |++| and |--| can only be applied to variables, not to
  4829. properties or array entries.
  4830.  
  4831. \subsection{Assignments}
  4832. There are four forms allowed are:^^{assignments}
  4833. \begindisplay
  4834. \<variable> |=| \<value>|;|\cr
  4835. \<byte-array>|->|\<entry> |=| \<value>|;|\cr
  4836. \<word-array>|-->|\<entry> |=| \<value>|;|\cr
  4837. \<object>|.|\<property> |=| \<value>|;|\cr
  4838. \enddisplay
  4839. For example:
  4840. \begintt
  4841. i=-15-j;   i=j-->1;   albatross.weight = albatross.weight + 1;
  4842. (paintpot.&roomlist)-->i = location;   turns++;
  4843. \endtt
  4844. One can also |inc| or |dec| (increment or decrement) a variable,
  4845. with |inc score;| being equivalent to the more modern |score++;|
  4846.  
  4847. Although these look logical, they are not allowed:
  4848. \begintt
  4849. paintpot.#roomlist = 5;
  4850. paintpot.&roomlist = array;
  4851. \endtt
  4852. because one cannot change the size or address of a property in play.
  4853.  
  4854. \warning A ^{division by zero} error (such as $n$|/0| or $n$|%0|)
  4855. may crash the game at run time.
  4856.  
  4857. \warning Attempting to write to a property which an object does not
  4858. have may crash the game at run time.
  4859.  
  4860. \subsection{Conditions}
  4861. A simple condition is
  4862. \begindisplay
  4863. \<a>\quad\<relation>\quad\<b>
  4864. \enddisplay
  4865. where the relation is one of^^{conditions}
  4866. \smallskip
  4867. \settabs 8 \columns
  4868. \+ &|==| && |a| equals |b|\cr
  4869. \+ &|~=| && |a| doesn't equal |b|\cr
  4870. \+ &|< > >= <=| && numeric (signed) comparisons\cr
  4871. \+ &|has| && object |a| has attribute |b|\cr
  4872. \+ &|hasnt| && object |a| hasnt attribute |b|\cr
  4873. \+ &|in| && object |a| is currently held by object |b|\cr
  4874. \+ &|notin| && ...is not...\cr
  4875. \smallskip
  4876. With |==| (and |~=|) only, one may also write the useful construction
  4877. \begindisplay
  4878. \<something> |==| \<v1> |[or| \<v2> |[or| \<v3>|]]|
  4879. \enddisplay^^|or|
  4880. which is true if the first something is any of the values given.  (An
  4881. idiosyncracy of Inform, for `hardware reasons', is that you can only have
  4882. three).  Conditions can be combined by the |&&| and
  4883. \orsign~ operators:
  4884. \begindisplay
  4885. \<condition1> |&&| \<condition2>\cr
  4886. \<condition1>~\orsign~ \<condition2>\cr
  4887. \enddisplay
  4888. true if both, or either (respectively) are true.  These are always tested
  4889. left to right until the outcome is known.  So, for instance,
  4890. \begindisplay
  4891. |i==1 | \orsign | Explode(2)==2|
  4892. \enddisplay
  4893. does not call |Explode| if |i| is 2.  Examples of legal conditions are:
  4894. \begindisplay
  4895. |i==1 or 2 or 3|\cr
  4896. |door has open |\orsign| (door has locked && key in player)|\cr
  4897. \enddisplay
  4898.  
  4899. \subsection{Built-in functions}
  4900. A very few functions are built into the language of Inform itself
  4901. (rather than written out longhand in the library files), but they
  4902. behave like any other routines.  They are:^^{built-in functions}
  4903. \smallskip
  4904. \settabs 8 \columns
  4905. \+ &|parent(obj)| && parent of object\cr
  4906. \+ &|sibling(obj)| && sibling of object\cr
  4907. \+ &|child(obj)| && eldest child of object\cr
  4908. \+ &|children(obj)| && number of (direct) children of object\cr
  4909. \+ &|eldest(obj)| && same as |child|\cr
  4910. \+ &|youngest(obj)| && youngest child of object\cr
  4911. \+ &|elder(obj)| && elder sibling of object\cr
  4912. \+ &|younger(obj)| && same as |sibling|\cr
  4913. \+ &|random(x)| && uniformly random number between 1 and $x$\cr
  4914. \+ &|indirect(addr)| && call routine with address |addr|\cr
  4915. \smallskip\par\noindent
  4916.  
  4917. \warning |random(0)| may cause a division by zero error.
  4918.  
  4919. \subsection{Printing commands}
  4920. A string on its own, such as^^{printing commands}
  4921. \begintt
  4922. "The world explodes in a puff of garlic.";
  4923. \endtt^^{puff of garlic}
  4924. is printed, with a new-line, and the current routine is returned from with
  4925. return value `true', i.e., 1.  In addition:
  4926. \smallskip
  4927. \settabs 8 \columns
  4928. \+ &|new_line| && prints a new-line\cr
  4929. \+ &|print ...| && prints the given things\cr
  4930. \+ &|print_ret ...| && prints, new-lines and returns 1\cr
  4931. \+ &|spaces n| && prints $n$ spaces\cr
  4932. \+ &|print_addr a| && print string at byte address |a|\cr
  4933. \+ &|print_paddr a| && print string at packed address |a|\cr
  4934. \+ &|font on/off| && turns proportional fonts on/off\cr
  4935. \+ &|style ...| && in Advanced games, sets text style\cr
  4936. \+ &|box "s1" ... "sn"| && in Advanced games, puts up quotation box\cr
  4937. \+ &|inversion| && prints out the current Inform version number\cr
  4938. \smallskip\par\noindent
  4939. |print| and |print_ret| take a comma-separated list of things to print out,
  4940. which can be: |"strings"|, |char n| (print the character with this ASCII
  4941. value) or |variable| (print out the variable as a signed number).  The
  4942. text |style| can be any of
  4943. \begintt
  4944. roman  reverse  bold  underline
  4945. \endtt
  4946.  
  4947. \subsection{Manipulating objects}
  4948. \smallskip
  4949. \settabs 8 \columns
  4950. \+ &|remove obj| && removes object from the tree\cr
  4951. \+ &|move o1 to o2| && moves |o1| to become youngest child of |o2|\cr
  4952. \+ &|give obj a1 ... an| && gives attributes to |obj|\cr
  4953. \smallskip\par\noindent
  4954. Attributes beginning with a |~| are taken away rather than given.
  4955.  
  4956. \subsection{Returning from routines}
  4957. \smallskip
  4958. \settabs 8 \columns
  4959. \+ &|return| && Return true, i.e. 1\cr
  4960. \+ &|return x| && Return value $x$\cr
  4961. \+ &|rtrue| && Return true, i.e. 1\cr
  4962. \+ &|rfalse| && Return false, i.e. 0\cr
  4963. \smallskip^^{returning from routines}
  4964.  
  4965. \subsection{Blocks of code}
  4966. A block of code may be a single instruction or a series of several, in which
  4967. case it must be enclosed in braces |{| and |}|.  Thus, for instance, in
  4968. \begintt
  4969. if (i==1) print "The water rises!";
  4970. if (i==2) { print "The water rises further...";
  4971.             water++;
  4972.           }
  4973. \endtt^^{blocks of code}^^{braces}
  4974. the ^|if| statements contain a block of code each.  Blocks can be nested
  4975. inside each other up to 32 deep.  An |if| statement (for example) is a
  4976. single statement even when it contains a great deal of code in its
  4977. block: so, for example,
  4978. \begintt
  4979. if (i>1) if (water<10) "The water is beginning to worry you.";
  4980. \endtt
  4981. is legal.  (One small exception: an |if| followed by an |else|
  4982. counts as two statements, and this means Inform handles ^{hanging elses}
  4983. rather poorly: so it's wise to brace so that |else| is clearly unambiguous.)
  4984.  
  4985. \subsection{Control constructs} Inform provides:^^{control constructs}
  4986. \begindisplay
  4987. |if| \<condition> \<block1> |[else| \<block2>|]|\cr
  4988. |while| \<condition> \<block>\cr
  4989. |do| \<block> |until| \<condition>\cr
  4990. |for (|\<initialise>|:|\<test>|:|\<each time>|)|\cr
  4991. |objectloop (|\<variable> |in| \<object>|)|\cr
  4992. |objectloop (|\<variable> |from| \<object>|)|\cr
  4993. |objectloop (|\<variable> |near| \<object>|)|\cr
  4994. |break|\cr
  4995. |jump| \<label>\cr
  4996. \enddisplay
  4997. Some of these will be familiar to most.  The ^|for| construct is essentially
  4998. the same as that in C, except for the colons |:| (which in C would be
  4999. semicolons).  Its carries out the initial assignment(s), then executes the
  5000. code for as long as the condition holds, executing the end assignment after
  5001. each pass through the code.  For instance,
  5002. \begintt
  5003. for (i=1:i<=10:i++) print i, " ";
  5004. \endtt
  5005. counts to 10.  All three clauses are optional, and the empty condition is
  5006. always true; multiple assignments can be made.  For instance:
  5007. \begintt
  5008. for (i=0,j=10:i<10:i++,j--) print i, " + ", j, " = ", i+j, "^";
  5009. for (::) print "Ha!^";
  5010. \endtt
  5011. the latter laughing maniacally forever.
  5012.  
  5013. ^|break| breaks out of the current loop (not quite the same as breaking out
  5014. the current block of code: |if| statements don't count as loops in this
  5015. regard).
  5016.  
  5017. ^|objectloop| goes through the object tree, and is extremely useful.  |from|
  5018. means from the given object through its siblings; |in| means through all
  5019. children of the given object, and |near| means through all children of the
  5020. parent of the object.  For instance, the following do the same thing:
  5021. \begintt
  5022. objectloop (x in lamp) { ... }
  5023. for (x=child(lamp): x~=0: x=sibling(x)) { ... }
  5024. \endtt
  5025. Note that the library creates a variable called |top_object| holding the
  5026. highest existing object number: so a way to ^{loop over every object}
  5027. defined in your own code is
  5028. \begintt
  5029. for (i=player+1: i<=top_object: i++) ...
  5030. \endtt^^|top object|
  5031. since |player| is always set to ^|selfobj|, which is the last object created
  5032. by the library.
  5033.  
  5034. \warning When looping through the object tree, be careful if you are altering
  5035. it at the same time.  For instance,
  5036. \begintt
  5037. objectloop (x in rucksack) remove x;
  5038. \endtt
  5039. is likely to go horribly wrong - it's safer not to cut down a tree
  5040. while actually climbing it.  The safe way is to keep lopping branches off,
  5041. \begintt
  5042. while (child(x)~=0) remove child(x);
  5043. \endtt
  5044.  
  5045. \exercise Write a routine to print out ^{prime factorisations} of numbers from
  5046. 2 to 100.
  5047.  
  5048. \answer{|Primes(100)|, where:\beginlines
  5049. |[ Primes i j k l;|
  5050. |  for (j=2:j<=i:j++)|
  5051. |  {   print j, " : "; l=j;|
  5052. |      while (l > 1)|
  5053. |      for (k=2:k<=l:k++)|
  5054. |          if (l%k == 0) { l=l/k; print k, " "; break; }|
  5055. |      new_line;|
  5056. |  }|
  5057. |];|
  5058. \endlines^^{prime factorisations}
  5059. (which was the first algorithm ever compiled by Inform).}
  5060.  
  5061. \subsection{Actions}
  5062. The commands
  5063. \begindisplay
  5064. |<| \<Action> |[|\<first-object> |[|\<second-object>|]]| |>|\cr
  5065. |<<| \<Action> |[|\<first-object> |[|\<second-object>|]]| |>>|\cr
  5066. \enddisplay 
  5067. cause the given ^{actions} to take place.  In the latter case, the current
  5068. routine then returns 1, or true.
  5069. \vfill\eject
  5070.  
  5071. \section{A2}{Library objects, properties and attributes}
  5072.  
  5073. \quote
  5074. A Model must be built which will get everything in without
  5075. a clash; and it can do this only by becoming intricate,
  5076. by mediating its unity through a great, and finely ordered,
  5077. multiplicity.
  5078. \widepoemby{^{C. S. Lewis} (1898-1963)}{The Discarded Image}
  5079.  
  5080. The library defines the following
  5081. ^{special objects}:^^{objects in library}
  5082. \medskip\ninepoint
  5083. \noindent |compass|\inpar To contain the directions.  A direction
  5084. object provides a |door_dir| property, and should have the
  5085. |direction| attribute.  A compass direction with |enterable|, if
  5086. there is one (which there usually isn't), will have an
  5087. |Enter| action converted to |Go|.
  5088.  
  5089. \noindent |n_obj|\inpar Both the object signifying the
  5090. abstract concept of `northness', and the `north wall' of
  5091. the current room.  (Thus, if a player types ``examine the north wall''
  5092. then the action |Examine n_obj| will be generated.)  Its
  5093. |door_dir| property holds the direction property it corresponds
  5094. to (|n_to|).^^{walls}^^{direction objects}
  5095.  
  5096.  
  5097. \noindent |s_obj|, |e_obj|, |w_obj|, |ne_obj|, |nw_obj|, |se_obj|,
  5098. |sw_obj|\inpar Similar.
  5099.  
  5100. \noindent |u_obj|, |d_obj|, |in_obj|, |out_obj| \inpar Similar:
  5101. the parser uses these if the player refers to ^{``ceiling''},
  5102. ^{``floor''}.  (|in_obj| and |out_obj| differ slightly, because
  5103. ``in'' and ``out'' are verbs with other effects in some cases.)
  5104.  
  5105. \noindent ^|thedark|\inpar A pseudo-room representing `being in
  5106. darkness'.  |location| is then set to this room, but the player
  5107. object is not moved to it.  Its |description| can be changed to
  5108. whatever ``It is dark here'' message is desired.
  5109.  
  5110. \noindent ^|selfobj|\inpar The player object.  However, do not
  5111. refer to |selfobj| directly: always refer to |player|, a variable
  5112. whose value is usually indeed |selfobj| but which might become
  5113. |green_frog| if the player is transformed into one.
  5114.  
  5115. \medskip\tenpoint
  5116. Here is a concise account of all the ^{normal rules} concerning
  5117. all the library's attributes.  (Except that: rules about how
  5118. the parser sorts out ambiguities are far too complicated to
  5119. include here, but should not concern designers anyway; and the
  5120. definitions of ``scope'' and ``darkness'' are given in the
  5121. main text.)  Of course these rules are all modifiable using
  5122. suitable |before| and |after| rules.  But a good deal of
  5123. pragmatism has gone into their design, or rather evolution.
  5124. ^^{attributes in library}
  5125. \medskip\ninepoint
  5126.  
  5127. \noindent ^|absent|\inpar A ^{`floating object'} (one with a
  5128. |found_in| property, which can appear in many different rooms)
  5129. which is |absent| will no longer appear in the game.
  5130.  
  5131. \noindent ^|animate|\inpar `Is alive (human or animal)'.  Can be
  5132. spoken to in ``richard, hello'' style; matches the |creature|
  5133. token in grammar; picks up ``him'' or ``her'' (according to
  5134. gender) rather than ``it'', likewise ``his''; an object the
  5135. player is changed into becomes |animate|; some messages read
  5136. ``on whom'', etc., instead of ``on which''; can't be taken;
  5137. its subobjects ``belong to'' it rather than ``are part of'' it;
  5138. messages don't assume it can be ``touched'' or ``squeezed'' as
  5139. an ordinary object can; the actions |Attack|, |ThrowAt| are
  5140. diverted to |life| rather than rejected as being `futile
  5141. violence'.
  5142.  
  5143. \noindent ^|clothing|\inpar Can be worn.
  5144.  
  5145. \noindent ^|concealed|\inpar `Concealed from view but present'.
  5146. The player's object has this; an object which was the player until
  5147. |ChangePlayer| happened, loses this property; a |concealed|
  5148. |door| can't be entered; does not appear in room descriptions.
  5149.  
  5150. \noindent ^|container|\inpar Affects scope and light (see definitions
  5151. in the main text); object lists recurse through it if |open| (or
  5152. |transparent|); may be described as closed, open, locked, empty;
  5153. a possession will give it a |LetGo| action if the player tries to
  5154. remove it, or a |Receive| if something is put in;
  5155. things can be taken or removed from it, or inserted into it,
  5156. but only if it is |open|; likewise for ``transfer'' and ``empty'';
  5157. room descriptions describe using |when_open| or |when_closed| if
  5158. given; if there is no defined |description|, an |Examine| causes the
  5159. contents to be searched (i.e. written out) rather than a message
  5160. ``You see nothing special about...''; |Search| only reveals the
  5161. contents of |container|s, otherwise saying ``You find nothing''.
  5162.  
  5163. \noindent ^|direction|\inpar If the player tries to walk this way
  5164. or enter it, a |Go| rather than |Enter| action is generated.
  5165. (Used only in one line of grammar, but a crucial one.)
  5166.  
  5167. \noindent ^|door|\inpar `Is a door or bridge'.  Room descriptions
  5168. describe using |when_open| or |when_closed| if given; and an |Enter|
  5169. action becomes a |Go| action.  If a |Go| has to go through this
  5170. object, then: if |concealed|, the player `can't go that way';
  5171. if not |open|, then the player is told either that this cannot
  5172. be ascended or descended (if the player tried ``up'' or ``down''
  5173. which went through it), or that it is in the way (otherwise);
  5174. but if neither, then its |door_to| property is consulted to
  5175. see where it leads; finally, if this is zero, then it is said
  5176. to `lead nowhere' (a safety precaution) and otherwise the player
  5177. actually moves to the location.
  5178.  
  5179. \noindent ^|edible|\inpar Can be eaten (and thus removed from game).
  5180.  
  5181. \noindent ^|enterable|\inpar Affects scope and light (see definitions
  5182. in the main text); only an |enterable| on the floor can be entered.
  5183.  
  5184. \noindent ^|female|\inpar Only applies to |animate|s (and cannot have
  5185. a |found_in| list for arcane reasons), and only affects the parser's
  5186. use of pronouns: it says ``her'' is appropriate but ``him'' and ``his''
  5187. are not.
  5188.  
  5189. \noindent ^|general|\inpar A general-purpose attribute, defined by
  5190. the library but never looked at or altered by it.  This is left
  5191. free to mean something different for each object: often used by
  5192. programmers for something like ``the puzzle for this object has been
  5193. solved''.
  5194.  
  5195. \noindent ^|light|\inpar `Is giving off light.'  (See definition of
  5196. `when there is light' in main text.)  Also: the parser understands
  5197. ``lit'', ``lighted'', ``unlit'' using this; inventories will
  5198. say ``(providing light)'' of it, and so will room descriptions if the
  5199. current |location| is ordinarily dark; it will never be automatically
  5200. put away into the player's |SACK_OBJECT| (as it might plausibly be
  5201. inflammable or the main light source).
  5202.  
  5203. \noindent ^|lockable|\inpar Can be locked or unlocked by a player
  5204. holding its key object, which is in the property |with_key|;
  5205. if a |container| and also |locked|, may be called ``locked'' in
  5206. inventories.
  5207.  
  5208. \noindent ^|locked|\inpar Can't be opened.   If a |container|
  5209. and also |locked|, may be called ``locked'' in inventories.
  5210.  
  5211. \noindent ^|moved|\inpar `Has once been held by the player'.  Objects
  5212. (immediately) owned by the player after |Initialise| has run are given
  5213. it; at the end of each turn, if an item is newly held by the player
  5214. and is |scored|, it is given |moved| and |OBJECT_SCORE| points are
  5215. awarded; an object's |initial| message only appears in room
  5216. descriptions if it is unmoved.
  5217.  
  5218. \noindent |on  |\inpar `Switched on.'  A |switchable| object with this
  5219. is described by |with_on| in room descriptions; it will be called
  5220. ``switched on'' by |Examine|.^^|on|
  5221.  
  5222.  
  5223. \noindent ^|open|\inpar `Open door or container'.  Affects scope and
  5224. light (see definitions in the main text), and: lists (such as inventories)
  5225. recurse through an |open| |container|; if a |container|, called open by some
  5226. descriptions; things can be taken or removed from an |open| |container|;
  5227. similarly inserted, transferred or emptied.  An |open| |door| can be
  5228. entered.  Described by |when_open| in room descriptions.
  5229.  
  5230. \noindent ^|openable|\inpar Can be opened or closed, unless |locked|.
  5231.  
  5232. \noindent ^|proper|\inpar Its short name is a proper noun, and never preceded
  5233. by ``the'' or ``The''.  The player's object must have this (so something
  5234. changed into will be given it).
  5235.  
  5236. \noindent ^|scenery|\inpar Not listed (by the library) in room descriptions, 
  5237. ``not portable'' to be taken; ``you are unable to'' pull, push, or turn it.
  5238.  
  5239. \noindent ^|scored|\inpar The player gets |OBJECT_SCORE| points for picking
  5240. it up for the first time; or, if a room, |ROOM_SCORE| points for visiting
  5241. it for the first time.
  5242.  
  5243. \noindent ^|static|\inpar ``Fixed in place'' if player tries to take, remove,
  5244. pull, push or turn.
  5245.  
  5246. \noindent ^|supporter|\inpar `Things can be put on top of it'.
  5247. Affects scope and light (see definitions in the main text);
  5248. object lists recurse through it; a possession will give it a
  5249. |LetGo| action if the player tries to remove it, or a |Receive|
  5250. if something is put in; things can be taken or removed from it,
  5251. or put on it; likewise for transfers; a player inside it is said
  5252. to be ``on'' rather than ``in'' it; room descriptions list
  5253. its contents in separate paragraphs if it is itself listed.
  5254.  
  5255. \noindent ^|switchable|\inpar Can be switched on or off; listed
  5256. as such by |Examine|; described using |when_on| or |when_off|
  5257. in room descriptions.
  5258.  
  5259. \noindent ^|talkable|\inpar Player can talk to this object in
  5260. ``thing, do this'' style.  (This is useful for microphones and
  5261. the like.)
  5262.  
  5263. \noindent ^|transparent|\inpar Affects scope and light
  5264. (see definitions in the main text: it roughly means `contents
  5265. always visible').  A |transparent| container is treated as if
  5266. it were |open| for printing of contents.
  5267.  
  5268. \noindent ^|visited|\inpar Given to a room when a |Look| first
  5269. happens there: if this room is |scored| then |ROOM_SCORE| points
  5270. are awarded.  Affects whether room descriptions are abbreviated
  5271. or not.
  5272.  
  5273. \noindent ^|workflag|\inpar Temporary flag used by Inform internals,
  5274. also available to outside routines; can be used to select items
  5275. for some lists printed by |WriteListFrom|.
  5276.  
  5277. \noindent ^|worn|\inpar `Item of clothing being worn'.  Should
  5278. only be held by an object being immediately carried by player.
  5279. Affects inventories; doesn't count towards the limit of
  5280. |MAX_CARRIED|; won't be automatically put away into the
  5281. |SACK_OBJECT|; a |Drop| action will cause a |Disrobe| action first;
  5282. so will |PutOn| or |Insert|; you can't insert or remove something
  5283. from a |worn| container.
  5284.  
  5285. \tenpoint\bigskip
  5286. Note that very few attributes sensibly apply to rooms: only really
  5287. |light|, |scored| and |visited|, together with |general| if you
  5288. choose to use it.  Note also that an object cannot be both a
  5289. |container| and a |supporter|; and that the old attribute ^|autosearch|,
  5290. which was in earlier releases, has been withdrawn as obselete.
  5291. \bigskip
  5292.  
  5293. Next, definitions of properties which sensibly apply to ``objects''
  5294. (meaning, things which are not rooms):^^{properties in library}
  5295. \ninepoint
  5296.  
  5297. \noindent ^|after|\inpar  List of rule routines to be applied in sequence
  5298. after an action takes place.  (For a room, receives all actions in that
  5299. room; for a player-object, all actions by the player as that object.)
  5300.  
  5301. \noindent ^|article|\inpar  Indefinite article for object (defaults to `a').
  5302.  
  5303. \noindent ^|before|\inpar  List of rule routines to be applied in sequence
  5304. before an action takes place.  (For a room, receives all actions in that
  5305. room; for a player-object, all actions by the player as that object.)
  5306.  
  5307. \noindent |cant_go|\inpar  Message to print (or routine to print one) when
  5308. a player tries to go in an impossible direction from this room (defaults to
  5309. ``You can't go that way.")^^|cant go|
  5310.  
  5311.  
  5312. \noindent ^|capacity|\inpar  Number of objects a |container| or |supporter|
  5313. can hold (defaults to 100); number of things the player can carry (when
  5314. the player is this object), initially set to |MAX_CARRIED| for the standard
  5315. player object.
  5316.  
  5317. \noindent ^|daemon|\inpar  Routine to run each turn (once activated by a
  5318. |StartDaemon| and until stopped by a |StopDaemon|).  Note: the same object
  5319. cannot have both a |daemon| and a |time_out|.
  5320.  
  5321. \noindent ^|describe|\inpar  Routine (only) to describe object: over-rides a
  5322. room's |description| to give main room description, if set; over-rides an
  5323. object's usual listing when it appears in a room description.
  5324.  
  5325. \noindent ^|description|\inpar  |Examine| message, or routine to print one out,
  5326. for an object; main room description, or routine to print one, for a room.
  5327.  
  5328. \noindent |door_dir|\inpar  Direction (that is, direction property, such as
  5329. |n_to|, not direction object) that a |door| goes via, or a routine
  5330. which returns this information; also used for direction objects, see
  5331. the |compass| notes above.^^|door dir|
  5332.  
  5333.  
  5334. \noindent |door_to|\inpar  Room that a |door| connects to, or routine
  5335. returning this; a value of 0 means `leads nowhere' (but this is not the
  5336. ideal way to implement such a door).^^|door to|
  5337.  
  5338.  
  5339. \noindent |each_turn|\inpar  String to print, or list of routines to
  5340. run, each turn that the object is in scope, after all timers and daemons
  5341. have run.^^|each turn|
  5342.  
  5343.  
  5344. \noindent |found_in|\inpar  List of rooms in which a ``floating object''
  5345. (that is, one present in multiple rooms) is found, unless it has |absent|,
  5346. in which case it is nowhere to be found.^^|found in|
  5347.  
  5348.  
  5349. \noindent ^|initial|\inpar  Initial description of object not yet picked up,
  5350. or routine to print one.
  5351.  
  5352. \noindent ^|invent|\inpar  Routine to change its inventory listing: see
  5353. main text.
  5354.  
  5355. \noindent ^|life|\inpar  List of rule routines to be applied in sequence
  5356. after an action making sense for an |animate| object takes place.
  5357.  
  5358. \noindent ^|name|\inpar  List of ^{dictionary words} referring to an object
  5359. (note: uniquely, these dictionary words are given in double quotes |"thus"|,
  5360. whereas in all other circumstances they would be |'thus'|; part tradition,
  5361. part defence against |'a'| single-letter ambiguity).  For
  5362. a room, lists dictionary words which ``do not need to be referred to in
  5363. this game''.
  5364.  
  5365. \noindent ^|number|\inpar  A general purpose property left free: conventionally
  5366. holding a number like ``number of turns' battery power left''.  (Except:
  5367. an object to be used as a player-object must provide one, and it isn't left
  5368. free.)
  5369.  
  5370. \noindent |parse_name|\inpar  Routine (only) to parse object's name
  5371. (this overrides the |name| and is also used in determining if two objects
  5372. are describably identical): see main text.^^|parse name|
  5373.  
  5374.  
  5375. \noindent ^|plural|\inpar  The plural name of an object (when in the presence
  5376. of others like it), or routine to print it.
  5377.  
  5378. \noindent |short_name|\inpar  The short name of an object (like ``brass lamp"),
  5379. or routine to print it.^^|short name|
  5380.  
  5381.  
  5382. \noindent |time_left|\inpar  Number of turns left until timer (if set,
  5383. which must be done using |StartTimer|) goes off.^^|time left|
  5384.  
  5385.  
  5386. \noindent |time_out|\inpar  Routine to run when timer goes off (having been
  5387. set by |StartTimer| and not in the mean time stopped by |StopTimer|).  Note:
  5388. the same object cannot have both a |daemon| and a |time_out|.^^|time out|
  5389.  
  5390.  
  5391. \noindent |when_closed|\inpar  |Look| description of something closed
  5392. (|door| or |container|), or routine to print one.^^|when closed|
  5393.  
  5394.  
  5395. \noindent |when_open|\inpar  |Look| description of something open
  5396. (|door| or |container|), or routine to print one.^^|when open|
  5397.  
  5398.  
  5399. \noindent |when_off|\inpar  |Look| description of a |switchable| which isn't
  5400. |on|, or routine to print one.^^|when off|
  5401.  
  5402. \noindent |when_on|\inpar  |Look| description of a |switchable| which is |on|,
  5403. or routine to print one.^^|when on|
  5404.  
  5405. \noindent |with_key|\inpar  Key object needed to lock/unlock a |lockable| object;
  5406. player must explicitly name it as the key being used and be holding it at the
  5407. time to use it.  May be 0, in which case no key fits.^^|with key|
  5408.  
  5409. \medskip\noindent together with the properties^^{direction properties}
  5410. \begintt
  5411. n_to   s_to    ne_to   se_to    u_to    d_to
  5412. e_to   w_to    nw_to   sw_to    in_to   out_to
  5413. \endtt
  5414. each of which can be map connections to other routines, or strings
  5415. (in which case they are printed if the player tries to go that way,
  5416. but the move is not allowed and no further action is taken),
  5417. or routines (in which case they are called to decide whether the
  5418. map connection exists or not, and if so where it leads).
  5419.  
  5420. \warning  Do not confuse |n_to| and so on with the 12 direction
  5421. objects, |n_obj| et al.^^{direction objects}
  5422.  
  5423. \tenpoint
  5424. \section{A3}{All the entry points, library routines and constants}
  5425.  
  5426. Entry points are routines which you can provide, if you choose to,
  5427. and which are called by the library routines to give you the option of
  5428. changing the rules.  All games {\bf must} define an ^|Initialise|
  5429. routine, which is obliged to set the |location| variable to a room;
  5430. the rest are optional.^^{entry points}
  5431. \ninepoint
  5432.  
  5433. \noindent ^|AfterLife|\inpar  When the player has died (a condition signalled
  5434. by the variable |deadflag| being set to a non-zero value other than
  5435. 2, which indicates winning), this routine is called: by setting
  5436. |deadflag=0| again it can resurrect the player.
  5437.  
  5438. \noindent ^|Amusing|\inpar  Called to provide an ``afterword" for players who
  5439. have won (for instance, it might advertise some features which a successful
  5440. player might never have noticed).  (But only if you have defined the
  5441. constant |AMUSING_PROVIDED| in your own code.)
  5442.  
  5443. \noindent ^|DarkToDark|\inpar  Called when a player goes from one dark room
  5444. into another one; a good excuse to kill the player off in anyone's book.
  5445.  
  5446. \noindent ^|DeathMessage|\inpar  Prints up ``You have died" style messages, for
  5447. |deadflag| values of 3 or more.  (If you choose ever to set |deadflag|
  5448. to such.)
  5449.  
  5450. \noindent ^|GamePostRoutine|\inpar  A kind of super-|after| rule, which
  5451. applies to all actions in the game, whatever they are:
  5452. use only in the last resort.
  5453.  
  5454. \noindent ^|GamePreRoutine|\inpar  A kind of super-|before| rule, which
  5455. applies to all actions in the game, whatever they are: use only in the last
  5456. resort.
  5457.  
  5458. \noindent ^|Initialise|\inpar  A compulsory routine, which must set |location|
  5459. and is convenient for miscellaneous initialising, perhaps for random settings.
  5460.  
  5461. \noindent ^|InScope|\inpar  An opportunity to place extra items in scope during
  5462. parsing, or to change the scope altogether.  (If |et_flag| is 1 when this is
  5463. called, the scope is being worked out for |each_turn| reasons; otherwise for
  5464. everyday parsing.)
  5465.  
  5466. \noindent ^|LookRoutine|\inpar  Called at the end of every |Look| description.
  5467.  
  5468. \noindent ^|NewRoom|\inpar  Called when the room changes, before any
  5469. description of it is printed.
  5470. (This happens no matter how the change of room occurred.)
  5471.  
  5472. \noindent ^|ParseNumber|\inpar  An opportunity to parse numbers in a different
  5473. (or additional) way.
  5474.  
  5475. \noindent ^|ParserError|\inpar  The chance to print different parser error
  5476. messages (like ``I don't understand that sentence'').
  5477.  
  5478. \noindent ^|PrintRank|\inpar  Completes the printing of the score.
  5479. (You might want to change this, so as to make the ranks something like
  5480. ^{``junior astronaut"} or ^{``master catburglar"} or whatever suits your game.)
  5481.  
  5482. \noindent ^|PrintVerb|\inpar  A chance to change the verb printed out in a
  5483. parser question (like ``What do you want to (whatever)?'') in case an unusual
  5484. verb via |UnknownVerb| has been constructed.  Returns true (or 1) if it has
  5485. printed something.
  5486.  
  5487. \noindent ^|PrintTaskName|\inpar  Prints the name of a game task
  5488. (such as ``driving the car").
  5489.  
  5490. \noindent ^|TimePasses|\inpar  Called after every turn (but not, for instance,
  5491. after a command like ``score" or ``save").  It's much more elegant to use timers
  5492. and daemons, or |each_turn| routines for individual rooms - using this
  5493. is a last resort.
  5494.  
  5495. \noindent ^|UnknownVerb|\inpar
  5496. Called by the parser when it hits an unknown verb,
  5497. so that you can transform it into a known one.
  5498.  
  5499. \tenpoint\bigskip
  5500.  
  5501. Library routines which are ``open to the public":^^{library routines}
  5502.  
  5503. \bigskip\ninepoint
  5504.  
  5505. \noindent |Achieved(task)|\inpar Indicate the |task| is achieved (which only
  5506. awards score the first time).
  5507.  
  5508. \noindent |AllowPushDir()|\inpar Signal that an attempt to push an object from
  5509. one place to another should be allowed.
  5510.  
  5511. \noindent |CDefArt(object)|\inpar Print the capitalised definite article and
  5512. short name of |object|.
  5513.  
  5514. \noindent |ChangePlayer(object, flag)|\inpar Cause the player at the keyboard to
  5515. play as the given object, which must have a |number| property supplied.  If
  5516. the |flag| is set to 1, then subsequently print messages like ``(as Ford
  5517. Prefect)'' in room description headers.  This routine, however, prints nothing
  5518. itself.
  5519.  
  5520. \noindent |DefArt(object)|\inpar Print the definite article and short name of
  5521. |object|.
  5522.  
  5523. \noindent |DoMenu(text,routine,routine)|\inpar Produce a menu.
  5524.  
  5525. \noindent ^|EnglishNumber(x)|\inpar Prints out |x| in English (e.g.,
  5526. ``two hundred and seventy-seven").
  5527.  
  5528. \noindent |HasLightSource(object)|\inpar Returns true if |object| ``has light''.
  5529.  
  5530. \noindent |InDefArt(object)|\inpar Print the indefinite article and short name
  5531. of |object|.
  5532.  
  5533. \noindent |NextWord()|\inpar Returns the next dictionary word in the player's
  5534. input, moving the word number |wn| on by one.  Returns -1 if the player's input
  5535. has run out, and 0 if the word is not in the dictionary.
  5536.  
  5537. \noindent |OffersLight(object)|\inpar Returns true if |object| ``offers light''.
  5538.  
  5539. \noindent |PlaceInScope(object)|\inpar Puts |object| into scope for the parser.
  5540.  
  5541. \noindent |PlayerTo(place, flag)|\inpar Move the player to |place|.  Unless
  5542. |flag| is given and is 1, describe the player's surroundings.
  5543.  
  5544. \noindent |PrintShortName(object)|\inpar Print the short name of |object|.
  5545. (This is protected against |object| having a meaningless value.)
  5546.  
  5547. \noindent |ScopeWithin(object)|\inpar Puts the contents of |object| into scope,
  5548. recursing downward according to the usual scope rules.
  5549.  
  5550. \noindent |SetTime(time,rate)|\inpar Set the game clock (a 24-hour clock) to the
  5551. given |time| (in seconds since the start of the day), to run at the given |rate|
  5552. $r$: $r=0$ means it does not run, if $r>0$ then $r$ seconds pass every turn,
  5553. if $r<0$ then $-r$ turns pass every second.
  5554.  
  5555. \noindent |ScopeWithin(object)|\inpar Puts the contents of |object|, recursing
  5556. downward according to the usual scope rules.
  5557.  
  5558. \noindent |StartDaemon(object)|\inpar Makes the daemon of |object| active, so
  5559. that its |daemon| routine will be called every turn.
  5560.  
  5561. \noindent |StartTimer(object, time)|\inpar Starts the timer of |object|, set
  5562. to go off in |time| turns, at which time its |time_out| routine will be called
  5563. (it must provide a |time_left| property).
  5564.  
  5565. \noindent |StopDaemon(object)|\inpar Makes the daemon of |object| inactive, so
  5566. that its |daemon| routine is no longer called.
  5567.  
  5568. \noindent |StopTimer(object)|\inpar Stops the timer of |object|, so that
  5569. it won't go off after all.
  5570.  
  5571. \noindent |TryNumber(wordnum)|\inpar Tries to parse the word at |wordnum| as a
  5572. number (recognising decimal numbers and English ones from ``one'' to
  5573. ``twenty''), returning -1000 if it fails altogether, or the number.
  5574. Values exceeding 10000 are rounded down to 10000.^^|TryNumber|
  5575.  
  5576. \noindent |WriteListFrom(object, style)|\inpar Write a list of |object| and its
  5577. siblings, with |style| a bitmap of options.
  5578.  
  5579. \noindent |YesOrNo()|\inpar Assuming that a question has already been printed,
  5580. wait for the player to type ``yes'' or ``no'', returning true or false
  5581. accordingly.
  5582.  
  5583. \tenpoint\bigskip
  5584.  
  5585. And, finally, the constants:
  5586.  
  5587. \bigskip\ninepoint
  5588.  
  5589. \noindent |AMUSING_PROVIDED|\inpar To indicate that an |Amusing| routine
  5590. is provided.
  5591.  
  5592. \noindent |DEBUG|\inpar To include the special ``debugging" verbs.
  5593.  
  5594. \noindent ^|Headline|\inpar Style of game and copyright message.
  5595.  
  5596. \noindent |MAX_CARRIED|\inpar Maximum number of (direct) possessions
  5597. the player can carry.
  5598.  
  5599. \noindent |MAX_SCORE|\inpar Maximum game score.
  5600.  
  5601. \noindent |MAX_TIMERS|\inpar Maximum number of timers or daemons active
  5602. at any one time (defaults to 32).
  5603.  
  5604. \noindent |NUMBER_TASKS|\inpar Number of ``tasks'' to perform.
  5605.  
  5606. \noindent |OBJECT_SCORE|\inpar Score for picking up a |scored| object
  5607. for the first time.
  5608.  
  5609. \noindent |ROOM_SCORE|\inpar Score for visiting up a |scored| room
  5610. for the first time.
  5611.  
  5612. \noindent |SACK_OBJECT|\inpar Object which acts as a ``rucksack'',
  5613. into which the game automatically tidies away things for the player.
  5614.  
  5615. \noindent ^|Story|\inpar Story name, conventionally in CAPITAL LETTERS.
  5616.  
  5617. \noindent |TASKS_PROVIDED|\inpar To indicate that ``tasks'' are provided.
  5618.  
  5619. \vfill\eject
  5620.  
  5621. \section{A4}{All the Inform error messages}
  5622.  
  5623. \ninepoint
  5624. Inform can produce about 230 different ^{error messages}.  The error messages
  5625. were tidied-up and made more consistent in Inform 5.4, which the text here
  5626. comes from, but earlier editions were similar.  Since interpreters can in
  5627. some cases crash horribly when given incorrect files, Inform never writes a
  5628. file which caused an error, though it will permit files which incurred only
  5629. warnings.
  5630.  
  5631. \subsection{Fatal errors}\medskip\noindent
  5632. To begin with, ^{fatal errors} (which stop Inform in its tracks) come in three
  5633. kinds, the first containing only this one:
  5634. \beginlines
  5635. |Too many errors: giving up|
  5636. \endlines
  5637. After 100 errors, Inform stops (in case it has been given the wrong source file
  5638. altogether).  Secondly, file input/output can go wrong.  Most commonly, Inform
  5639. has the wrong filename:
  5640. \beginlines
  5641. |Couldn't open input file <filename>|
  5642. |Couldn't open output file <filename>|
  5643. |Couldn't open transcript file <filename>|
  5644. |Couldn't open debugging information file <filename>|
  5645. |Couldn't open temporary file 1 <filename>|
  5646. |Couldn't open temporary file 2 <filename>|
  5647. |Too many files have included each other: increase #define MAX_INCLUSION_DEPTH|
  5648. \endlines
  5649. (Temporary files are used (on most machines) for temporary storage space
  5650. during compilation.  They are removed afterwards.)
  5651. The last error only occurs if 5 files all include each other.  Increasing this
  5652. |#define| means re-compiling Inform from its C source, a drastic measure.
  5653. The remaining file-handling errors usually mean that the disc is full:
  5654. something has gone wrong with an already-open file.
  5655. \beginlines
  5656. |I/O failure: couldn't read from source file|
  5657. |I/O failure: couldn't write to temporary file 1|
  5658. |I/O failure: couldn't reopen temporary file 1|
  5659. |I/O failure: couldn't read from temporary file 1|
  5660. |I/O failure: couldn't write to temporary file 2|
  5661. |I/O failure: couldn't reopen temporary file 2|
  5662. |I/O failure: couldn't read from temporary file 2|
  5663. |I/O failure: couldn't write to story file|
  5664. |I/O failure: couldn't write to transcript file|
  5665. |I/O failure: can't write to debugging information file|
  5666. \endlines
  5667. The third class of fatal error is Inform ^{running out of memory}.  It might
  5668. fail drastically, having not enough memory to get started, as follows...
  5669. \beginlines
  5670. |Couldn't allocate memory|
  5671. |Couldn't allocate memory for an array|
  5672. \endlines
  5673. (There are four similar |hallocate| errors unique to the PC `Quick C' port.)
  5674. More often it will run out in the course of compilation, like so:
  5675. \beginlines
  5676. |The memory setting <setting> (which is <value> at present) has been exceeded.|
  5677. |Try running Inform again with $<setting>=<some-larger-number> on the command line.|
  5678. \endlines
  5679. For details of the ^{memory settings}, see the next section.
  5680.  
  5681. \subsection{Errors}\medskip\noindent
  5682. There are a few conventions.  Anything in double-quotes is a quotation from
  5683. your source code; other strings are in single-quotes.  A message like
  5684. \beginstt
  5685. Expected ... but found "..."
  5686. \endtt
  5687. means that Inform expected something different from what it found; if it
  5688. doesn't say what it found, this usually means it found nothing (i.e. the
  5689. statement was incomplete).  Messages in the form
  5690. \beginstt
  5691. No such ... as "..."
  5692. Not a ...: "..."
  5693. \endtt
  5694. mean that a name is unrecognised in the former case (say, a typing error
  5695. might produce this), or is recognised but means something else in the latter
  5696. case (an attempt to use a routine where a property is expected would give
  5697. such an error).
  5698.  
  5699. To begin with, the source-code format may go awry:
  5700. \beginlines
  5701. |Too many tokens on line (note: to increase the maximum, set|
  5702. |    $MAX_TOKENS=some-bigger-number on the Inform command line)|
  5703. |Line too long (note: to increase the maximum length, set|
  5704. |    $BUFFER_LENGTH=some-bigger-number on the Inform command line)|
  5705. |Too much text for one pair of "s to hold|
  5706. |Too much text for one pair of 's to hold|
  5707. |Open quotes " expected for text but found <text>|
  5708. |Close quotes " expected for text but found <text>|
  5709. \endlines
  5710. (Usually |BUFFER_LENGTH| allows about 2000 characters per line.)
  5711. When giving something (such as an object) an internal name, there are
  5712. rules to be obeyed; for instance, you can't give an object the same name
  5713. as a property already declared:
  5714. \beginlines
  5715. |Symbol name expected|
  5716. |Symbol names are not permitted to start with an '_'|
  5717. |Symbol name is too long: <text>|
  5718. |Duplicated symbol name: <text>|
  5719. \endlines^^{symbol names}
  5720. At the top level, the most common ``no such command'' error is
  5721. \beginlines
  5722. |Expected an assignment, command, directive or opcode but found <text>|
  5723. \endlines
  5724. which means Inform didn't even understand the first word of the command.
  5725. Directives to Inform can produce the following errors:
  5726. \beginlines
  5727. |All 32 attributes already declared (compile as Advanced game to get an extra 16)|
  5728. |All 48 attributes already declared|
  5729. |All 30 properties already declared (compile as Advanced game to get an extra 32)|
  5730. |All 62 properties already declared|
  5731. |Expected an attribute name after 'alias'|
  5732. |Expected a property name after 'alias'|
  5733. |'alias' incompatible with 'long'|
  5734. |'alias' incompatible with 'additive'|
  5735. |'alias' refers to undefined attribute <text>|
  5736. |'alias' refers to undefined property <text>|
  5737. |All 235 global variables already declared|
  5738. |Expected 'string', 'data', 'initial', 'initstr' or '=' but found <text>|
  5739. \endlines^^|alias|^^{global variables}
  5740. Use of |alias| is rare (except inside the library files).  The last of these
  5741. errors means that a global variable has been wrongly initialised, and a
  5742. common cause of this is typing, say, |global trolls 5;| instead of
  5743. |global trolls = 5;|.
  5744. \beginlines
  5745. |'*' divider expected, but found <text>|
  5746. |No such token as <text>|
  5747. |Expected '=' after 'scope' but found <text>|
  5748. |Expected routine after 'scope=' but found <text>|
  5749. |Expected routine after 'noun=' but found <text>|
  5750. |'=' is only legal here as 'noun=Routine'|
  5751. |'->' clause missing|
  5752. |No such action routine as <text>|
  5753. |Not an action: <text>|
  5754. |Too many lines of grammar for verb: increase #define MAX_LINES_PER_VERB|
  5755. |There is no previous grammar for the verb <text>|
  5756. |Two different verb definitions refer to <text>|
  5757. |Expected 'replace', 'last' or 'first' but found <text>|
  5758. \endlines^^{parser speed}
  5759. These are the ^{grammatical errors}, the last three concerning |extend|ed
  5760. verb definitions.  
  5761. Normally one gets 16 grammar lines per verb.  It's probably better to write
  5762. grammar more carefully (using routines to parse adjectives more carefully,
  5763. for instance) than to exceed this, as the game parser will otherwise slow
  5764. down.  The object/class definition errors are largely self-explanatory:
  5765. \beginlines
  5766. |Object/class definition finishes with ','|
  5767. |Two commas ',' in a row in object/class definition|
  5768. |No such attribute as <text>|
  5769. |No such class as <text>|
  5770. |Expected 'with', 'has' or 'class' in object/class definition but found <text>|
  5771. |Expected an (internal) name for object but found the string <text>|
  5772. |An object must be defined after the one which contains it: (so far)|
  5773. |    there is no such object as <text>|
  5774. |Not an object: <text>|
  5775. |No such property as <text>|
  5776. |Not a property: <text>|
  5777. \endlines^^{object errors}^^{class errors}
  5778. Miscellaneous errors complete the list produced by mostly-uncommon directives:
  5779. \beginlines
  5780. |Expected ';' after 'include <file>' but found <text>|
  5781. |A 'switches' directive must come before constant definitions|
  5782. |Expected 'score' or 'time' after 'statusline' but found <text>|
  5783. |The serial number must be a 6-digit date in double-quotes|
  5784. |The version number must be 3 to 6: 3 for Standard games and 5 for Advanced|
  5785. |Expected 'on' or 'off' after 'font' but found <text>|
  5786. |Defaulted constants can't be strings|
  5787. |Must specify 0 to 3 variables in 'stub' routine|
  5788. |Expected 'full' or nothing after 'etrace' but found <text>|
  5789. |Too many abbreviations declared|
  5790. |All abbreviations must be declared together|
  5791. |It's not worth abbreviating <text>|
  5792. |Expected a 'string' value|
  5793. |No such directive as <text>|
  5794. \endlines
  5795. Conditional compilation happens as a result of one of |#IFDEF|, |#IFV3| or
  5796. |#IFV5|.  (The former tests whether a constant is defined; the latter test
  5797. for version-3 (Standard) games or version-5 (Advanced) games.)  An |#IFNOT|
  5798. section is optional but the closing |#ENDIF| is compulsory.  In these error
  5799. messages |#IF...| means any of the three opening clauses.
  5800. \beginlines
  5801. |'#IF...' nested too deeply: increase #define MAX_IFDEF_DEPTH|
  5802. |'#ENDIF' without matching '#IF...'|
  5803. |'#IFNOT' without matching '#IF...'|
  5804. |Two '#IFNOT's in the same '#IF...'|
  5805. |End of file reached inside '#IF...'|
  5806. \endlines^^{conditional compilation}
  5807. Routines begin with a |[| and some local variables and end with |]|:
  5808. \beginlines
  5809. |Routine has more than 15 local variables|
  5810. |The earliest-defined routine is not allowed to have local variables|
  5811. |Expected local variable but found ',' or ':' (probably the ';' after the|
  5812. |    '[ ...' line was forgotten)|
  5813. |Misplaced ']'|
  5814. |Comma ',' after ']' can only be used inside object/class definitions|
  5815. |Expected ',' or ';' after ']' but found <text>|
  5816. |Expected ';' after ']' but found <text>|
  5817. \endlines^^{routine errors}
  5818. The error messages for expressions are fairly simple.  Note, however, that
  5819. one is not allowed to type, say, |lamp.number++;| but must instead write
  5820. |lamp.number = lamp.number + 1;| (the ^|++| and ^|--| operators
  5821. can only be applied to variables, not properties).
  5822. \beginlines
  5823. |Expected condition but found expression|
  5824. |Unexpected condition|
  5825. |Expected an assignment but found <text>|
  5826. |Expected an assignment but found an expression|
  5827. |Attempt to use void as a value|
  5828. |Attempt to use an assignment as a value|
  5829. |Attempt to use a condition as a value|
  5830. |Operator has too few arguments|
  5831. |Operator has too many arguments|
  5832. |'++' and '--' can only apply directly to variables|
  5833. |At most three values can be separated by 'or'|
  5834. |'or' can only be used with the conditions '==' and '~='|
  5835. |Too many brackets '(' in expression|
  5836. |Brackets '(' too deeply nested|
  5837. |Missing bracket ')' in function call|
  5838. |Spurious comma ','|
  5839. |Misplaced comma ','|
  5840. |Wrong number of arguments to system function|
  5841. |'children' takes a single argument|
  5842. |'youngest' takes a single argument|
  5843. |'elder' takes a single argument|
  5844. |'indirect' takes at least one argument|
  5845. |Type mismatch in argument <text>|
  5846. |A function may be called with at most 3 arguments|
  5847. |Malformed statement 'Function(...);'|
  5848. |Spurious terms after function call|
  5849. |Spurious terms after assignment|
  5850. |Spurious terms after expression|
  5851. \endlines^^{expression errors}
  5852. Next, constants.  Note that dictionary words cannot start with a
  5853. non-alphabetic character, which means that Infocom-style ``debugging verbs''
  5854. which traditionally begin with a |#| are not allowed.
  5855. \beginlines
  5856. |No such variable as <text>|
  5857. |No such constant as <text>|
  5858. |Not a constant: <text>|
  5859. |Reserved word as constant: <text>|
  5860. |No such routine as <text>|
  5861. |Dictionary words must begin with a letter of the alphabet|
  5862. |Dictionary word not found for constant <text>|
  5863. \endlines^^{dictionary errors}
  5864. Loop constructs: note that `old-style' |for| loops are a rather obselete
  5865. form (e.g. |for i 1 to 10|), and the more flexible style |for (i=1:i<=10:i++)|
  5866. is now preferred.
  5867. \beginlines
  5868. |'if' statement with more than one 'else'|
  5869. |'else' attached to a loop block|
  5870. |'for' loops too deeply nested|
  5871. |':' expected in 'for' loop|
  5872. |Second ':' expected in 'for' loop|
  5873. |Concluding ')' expected in 'for' loop|
  5874. |'to' missing in old-style 'for' loop|
  5875. |'to' expected in old-style 'for' loop|
  5876. |Final value missing in old-style 'for' loop|
  5877. |'{' required after an old-style 'for' loop|
  5878. |Old-style 'for' loops must have simple final values|
  5879. |Open bracket '(' expected in 'objectloop'|
  5880. |'objectloop' must be 'from', 'near' or 'in' something|
  5881. |Close bracket ')' expected in 'objectloop'|
  5882. |Braces '{' are compulsory unless the condition is bracketed|
  5883. |Unmatched '}' found|
  5884. |Brace mismatch in previous routine|
  5885. \endlines^^{brace mismatch}
  5886. Inform checks the level of braces when a routine closes so that it can
  5887. recover as quickly as possible from a mismatch; this last error means at
  5888. least one brace is still open when the routine finishes.
  5889. \beginlines
  5890. |The object to 'give' to must be a variable or constant|
  5891. |Expected some attributes to 'give'|
  5892. |Expected 'to <object>' in 'move'|
  5893. |Expected 'to' in 'move' but found <text>|
  5894. |Expected ',' in 'print' list but found <text>|
  5895. |Expected 'style' to be 'roman', 'bold', 'underline' or 'reverse' but found <text>|
  5896. |Expected a parse buffer for 'read'|
  5897. |Expected some properties to 'write'|
  5898. |The object to 'write' must be a variable or constant|
  5899. |Expected property value to 'write'|
  5900. |Expected 'byte' or 'word' in 'put'|
  5901. |Expected 'byte' or 'word' in 'put' but found <text>|
  5902. \endlines
  5903. These are miscellaneous commands and |put| and |write| are quite obselete.
  5904. Only action commands like |<Take brass_lantern>| remain:
  5905. \beginlines
  5906. |Action name too long or a string: perhaps a statement accidentally ended|
  5907. |    with a comma?|
  5908. |Action commands must take the form '< Action ... >'|
  5909. |The longest action command allowed is '<Action noun second>'|
  5910. |Angle brackets do not match|
  5911. |Action given in constant does not exist|
  5912. |Action name over 60 characters long: <text>|
  5913. |Expected ':' (after action) but found <text>|
  5914. \endlines
  5915. The first of these may be caused by something like:
  5916. \beginstt
  5917.      "You load the crossbow bolt.",
  5918.    Drop:  "The bolt falls to the floor with a thump.";
  5919. \endtt
  5920. where a comma has been typed instead of a semicolon after the first string,
  5921. so that Inform thinks you are giving a rule for two actions, one being |Drop|
  5922. and the other apparently called |"You load the crossbow bolt."|.
  5923.  
  5924. \subsection{Internal and assembler errors}\medskip\noindent
  5925. By now we have descended to the ninth circle of Inform: the assembler.
  5926. These errors are fairly unmysterious (if only because they seldom happen),
  5927. but sometimes one is told something odd like
  5928. \beginstt
  5929. No such label as _f456
  5930. \endtt
  5931. which is caused by Inform failing to recover properly from a previous
  5932. brace mismatch error.  Just ignore this and fix the earlier error (which will
  5933. also have been reported).  The ``no such variable'' error is occasionally
  5934. seen when an unknown variable is first referred to by being written to.
  5935. \beginlines
  5936. |No such assembly opcode as <text>|
  5937. |Too many arguments|
  5938. |Can't store to that (no such variable)|
  5939. |Branch too far forward: use '?'|
  5940. |No such return condition for branch|
  5941. |Can't branch to a routine, only to a label|
  5942. |No such label as <text>|
  5943. |Not a label: <text>|
  5944. \endlines^^{assembler errors}
  5945. To conclude with, there are a few internal error messages:
  5946. \beginlines
  5947. |A label has moved between passes because of a low-level error just before|
  5948. |    (perhaps an improper use of a routine address as a constant)|
  5949. |Object has altered in memory usage between passes: perhaps an attempt to|
  5950. |    use a routine name as value of a small property|
  5951. |Duplicated system symbol name <text>|
  5952. |Internal error - unknown directive code|
  5953. |Internal error - unknown compiler code|
  5954. \endlines^^{internal errors}
  5955. The last three should not happen.  The first two occasionally do, and cause
  5956. some confusion.  Inform performs two tests regularly as a safeguard to make
  5957. sure that code has not come out substantially different in its two passes.
  5958. The first failure occurs in code, the second for object/class definitions.
  5959. Whatever caused this should be something unusual, low-level and just
  5960. before the error occurred: if you get these errors with innocent high-level
  5961. code, then probably Inform should provide a suitable error message, so
  5962. please email the author with a sample of offending code.
  5963.  
  5964. \subsection{Warnings}\medskip\noindent
  5965. Inform can produce any number of warnings without shutting down.  Note
  5966. that Inform tries to give only warnings when it hits Advanced-game features
  5967. in what is to be a Standard game, for the sake of portability.  Nevertheless
  5968. it is probably better to use |#IFV3| and |#IFV5| clauses around any pieces
  5969. of code which are to be different in these two versions (if, indeed, you
  5970. want two different versions).
  5971. \beginlines
  5972. |Local variable unused: <text>|
  5973. |Since it is defined before inclusion of the library, game-play will begin|
  5974. |    not at 'Main' but at the routine <text>|
  5975. |Ignoring Advanced-game status routine|
  5976. |Ignoring this Advanced-game command|
  5977. |Missing ','?  Property data seems to contain the property name <text>|
  5978. |Standard-game limit of 8 bytes per property exceeded (use Advanced to get|
  5979. |    64), so truncating property <text>|
  5980. |Ignoring Advanced-game opcode <text>|
  5981. |Ignoring Standard-game opcode <text>|
  5982. \endlines^^{warnings}^^{Advanced games}^^{Standard games}
  5983. \tenpoint
  5984.  
  5985. \section{A5}{Compiler options and memory settings}
  5986.  
  5987. \widepoem
  5988. I was promised a horse, but what I got instead
  5989. was a tail, with a horse hung from it almost dead.
  5990. \quoteby{Palladas of Alexandria, translated by Tony Harrison}
  5991.  
  5992. \ninepoint
  5993. \noindent {\it
  5994. The reader is warned that some details in this section are slightly
  5995. different on different machines.}
  5996. \medskip
  5997. \noindent
  5998. On most machines, Inform is run from the command line, by a command like
  5999. \beginstt
  6000. inform -xv5 balances
  6001. \endtt
  6002. and simply typing |inform| will produce a good deal of help information
  6003. about the command line options available.  The ^{command line syntax} is
  6004. \begindisplay
  6005. |inform| \<switches> \<settings> \<source file> \<output file>
  6006. \enddisplay
  6007. where only the \<source file> is mandatory.  (By default, the full names to
  6008. give the source and output files are derived in a way suitable for the machine
  6009. Inform is running on: on a PC, for instance, |advent| may be understood as
  6010. asking to compile |advent.inf| to |advent.z5|.)
  6011. \medskip
  6012. The switches are given in one or more groups, preceded by a minus sign |-|
  6013. in the usual Unix command-line style.  The current list of legal switches is:
  6014. \beginlines
  6015. |  a   list assembly-level instructions compiled|
  6016. |  b   give statistics and/or line/object list in both passes|
  6017. |  c   more concise error messages|
  6018. |  d   contract double spaces after full stops in text|
  6019. |  e   economy mode (slower): make use of declared abbreviations|
  6020. |  f   frequencies mode: show how useful abbreviations are|
  6021. |  g   with debugging code: traces all function calls|
  6022. |  h   print this information|
  6023. |  i   ignore default switches set within the file|
  6024. |  j   list objects as constructed|
  6025. |  k   output Infix debugging information to "Game_Debug"|
  6026. |  l   list all assembly lines|
  6027. |  m   say how much memory has been allocated|
  6028. |  n   print numbers of properties and attributes|
  6029. |  o   print offset addresses|
  6030. |  p   give percentage breakdown of story file|
  6031. |  r   record all the text to "Game_Text"|
  6032. |  s   give statistics|
  6033. |  t   trace Z-code assembly|
  6034. |  u   work out most useful abbreviations|
  6035. |  v3  compile to version-3 (Standard) story file|
  6036. |  v4  compile to version-4 (Plus) story file|
  6037. |  v5  compile to version-5 (Advanced) story file|
  6038. |  v6  compile to version-6 (graphical) story file|
  6039. |  w   disable warning messages|
  6040. |  x   print # for every 100 lines compiled (in both passes)|
  6041. |  z   print memory map of the Z-machine|
  6042. |  T   enable throwback of errors in the DDE|
  6043. \endlines^^{compiler switches}^^{switches (on command line)}
  6044. (Thus, as long as your name doesn't have a `q' or `y' in it, you can
  6045. amuse yourself typing your name in as a switch and see what it does.)
  6046. Note that these switches can also be selected by putting a |switches|
  6047. directive into the source code before anything else, such as
  6048. \beginstt
  6049.     Switches xdv5s;
  6050. \endtt
  6051. The most useful switches are |v3| and |v5|, which choose between Standard
  6052. and ^{Advanced games}^^{Standard games}.  For example, the above line is
  6053. from the example game ^{`Advent'}, which is consequently compiled to an
  6054. Advanced game.  (If no choice is stated, a Standard game results.)  The
  6055. options |v4| and |v6| are provided for completeness but their use is not
  6056. recommended.
  6057.  
  6058. Many of the remaining switches make Inform produce extra output, but do
  6059. not affect its compilation:
  6060. \medskip
  6061.  
  6062. \noindent |a b l m n t|\quad are tracing options to help with maintaining
  6063. Inform, or for debugging assembly language programs
  6064.  
  6065. \noindent |o p s z|\quad will print out information about the final game file,
  6066. the |s| (^{statistics}) option being particularly useful to keep track of how
  6067. large the game is growing
  6068.  
  6069. \noindent |c w T|\quad in |c| mode, Inform does not quote whole source lines
  6070. together with error messages; in |w| mode it suppresses warnings; in |T|
  6071. mode, which is only present on the Acorn Archimedes, error throwback
  6072. will occur in the `Desktop Development Environment'
  6073.  
  6074. \noindent |f|\quad indicates roughly how many bytes the abbreviations saved
  6075.  
  6076. \noindent |h|\quad prints out the help information (and is equivalent to
  6077. just typing |inform|)
  6078.  
  6079. \noindent |j x|\quad make Inform print out steady text to prove that it's
  6080. still awake: on very slow machines this may be a convenience
  6081.  
  6082. \noindent |k|\quad writes a ^{``debugging information'' file} for the use of
  6083. the ^{Infix} debugger (similarly, the filename is something suitable for
  6084. the machine)
  6085.  
  6086. \noindent |r|\quad is intended to help with proof-reading the text of a game,
  6087. and transcribes all of the text in double-quotes to the given file (whose
  6088. name is something suitable for the machine)
  6089.  
  6090. \noindent |u|\quad will try to work out a good set of abbreviations to
  6091. declare for your game, but {\it extremely slowly} (a matter of hours) and
  6092. {\it consuming very much memory} (perhaps a megabyte)
  6093. \medskip
  6094. This leaves three more switches which actually alter the game file which
  6095. Inform would compile:
  6096. \medskip
  6097. \noindent |d|\quad converts text like
  6098. \beginstt
  6099. "...with a mango.  You applaud..."
  6100. \endtt
  6101. into the same with only a single space after the full stop, which will
  6102. prevent an interpreter from displaying a spurious space at the beginning
  6103. of a line when a line break happens to occur exactly after the full stop;
  6104. this is to help typists who habitually double-space
  6105. ^^{double spacing}
  6106.  
  6107. \noindent |e|\quad only in ^{`economy' mode} does Inform actually process
  6108. abbreviations, because this is seldom needed and slows the compiler by
  6109. 10\% or so; the game file should not play any differently if compiled
  6110. this way, but will probably be shorter, if your choice of ^{abbreviations}
  6111. was sensible
  6112.  
  6113. \noindent |g|\quad will make Inform automatically compile trace-printing
  6114. code on every function call; in play this will produce reams of text (several
  6115. pages between each chance to type commands) but is sometimes useful.  Note
  6116. that in Inform 5.3 or later, this can be set on an individual command by
  6117. writing |*| as its first local variable, without use of the |g| switch
  6118.  
  6119. \noindent |i|\quad overrides any switches set by |switches| directives in
  6120. the source code; so that the game can be compiled with different options
  6121. without having to alter that source code.
  6122. \bigskip
  6123.  
  6124. Inform's ^{memory management} is about as flexible as it can be given that it
  6125. has to run in some quite hostile environments.  In particular, it is unable
  6126. to increase the size of any stretch of memory once allocated, so if it runs
  6127. out of anything it has to give up.  If it does run out, it will produce an
  6128. error message saying what it has run out of and how to provide more.
  6129.  
  6130. There are two main choices: |$small| and |$large|.  (Which one is the default
  6131. depends on the computer you use.)  Even |$small| is large enough to compile
  6132. all the example games, including ^{`Advent'}.  |$large| is large enough to
  6133. compile almost anything (including the largest version of ^{`Curses'} which
  6134. ever existed, a draft very close to 256K long).
  6135.  
  6136. A typical game, compiled with |$large|, will cause Inform to allocate about
  6137. 336K of memory: and the same game about 100K less under |$small|.  (These
  6138. values will be rather lower if the computer Inform runs on has 16-bit
  6139. integers.)  In addition, Inform physically occupies about 170K (on my
  6140. computer).  Thus, the total ^{memory consumption} of the compiler at work
  6141. will be between 4 to 500K.
  6142.  
  6143. Running
  6144. \beginstt
  6145.     inform $list
  6146. \endtt^^{memory settings}^^{small memory}^^{large memory}
  6147. will list the various settings which can be changed, and their current
  6148. values.  Thus one can compare small and large with:
  6149. \beginstt
  6150.     inform $small $list
  6151.     inform $large $list
  6152. \endtt
  6153. If Inform runs out of allocation for something, it will generally print an
  6154. error message like:
  6155. \beginstt
  6156.    "Game", line 1320: Fatal error: The memory setting MAX_OBJECTS (which
  6157.    is 200 at present) has been exceeded.  Try running Inform again with
  6158.    $MAX_OBJECTS=<some-larger-number> on the command line.
  6159. \endtt
  6160. and indeed
  6161. \beginstt
  6162.     inform $MAX_OBJECTS=250 game
  6163. \endtt
  6164. (say) will tell Inform to try again, reserving more memory for objects this
  6165. time.  Note that settings are made from left to right, so that for instance
  6166. \beginstt
  6167.     inform $small $MAX_ACTIONS=200 ...
  6168. \endtt
  6169. will work, but
  6170. \beginstt
  6171.     inform $MAX_ACTIONS=200 $small ...
  6172. \endtt
  6173. will not because the |$small| changes |MAX_ACTIONS| again.
  6174.  
  6175. Changing some settings has hardly any effect on memory usage, whereas others
  6176. are expensive to increase.  To find out about, say, |MAX_VERBS|, run
  6177. \beginstt
  6178.     inform $?MAX_VERBS
  6179. \endtt
  6180. (note the question mark) which will print some very brief comments.
  6181. \ninepoint
  6182.  
  6183. \immediate\closeout\ans
  6184. \vfill\eject
  6185. \section{A6}{Answers to all the exercises}
  6186. \outer\def\ansno #1:{\medbreak
  6187.   \noindent\llap{$\bullet$\rm\kern.15em}%
  6188.   {\ninebf \bf #1}\quad}
  6189.  
  6190. \ansno1:
  6191. {\beginlines
  6192. |Nearby cone "green cone"|
  6193. |  with name "green" "cone" "emerald" "marzipan",|
  6194. |       describe|
  6195. |       [; if (cone has moved)|
  6196. |              "A misshapen cone of green marzipan sits here.";|
  6197. |          "Nearby is an emerald green cone, one foot high.";|
  6198. |       ],|
  6199. |       description "The cone seems to be made of emerald-coloured \ |
  6200. |                    marzipan.",|
  6201. |       before|
  6202. |       [; Eat: if (random(100) <= 30)|
  6203. |               {   deadflag = 1;|
  6204. |                   "Unfortunately, you seem to be allergic to almonds.";|
  6205. |               }|
  6206. |               "You nibble at a corner of the cone.";|
  6207. |       ],|
  6208. |       after|
  6209. |       [; Take: "Taken.  (Your hands are smeared with marzipan.)";|
  6210. |          Drop: cone.description = "The cone is a vague green mess.";|
  6211. |                "The cone drops to the floor and sags a little.";|
  6212. |       ],|
  6213. |  has  edible;|
  6214. \endlines
  6215. The old |initial| message has gone.  Instead, we have provided a
  6216. |describe| routine.  Whenever the game has to describe the cone in the
  6217. description of a place, it will call this routine.  The |moved| attribute
  6218. is held only by an object which has at some time in the past been taken.  So
  6219. the cone is now perfect and untouched until taken and dropped, whereupon
  6220. it becomes misshapen.  Also, the act of dropping the cone now changes the
  6221. description which appears when a player examines it.}
  6222.  
  6223. \ansno2:
  6224. {You may be surprised how many actions take place: often more than one
  6225. per turn.}
  6226.  
  6227. \ansno3:
  6228. {|if (obj.&door_to == 0) { ... }|}
  6229.  
  6230. \ansno4:
  6231. {Define four objects along the lines of:
  6232. \beginlines
  6233. |Object white_obj "white wall" compass|
  6234. |  with name "white" "sac" "wall", article "the", door_dir n_to|
  6235. |  has  direction scenery;|
  6236. \endlines^^{world colours}^^{Mayan directions}^^{direction objects}
  6237. and add the following line to |Initialise|:
  6238. \beginlines
  6239. |remove n_obj; remove e_obj; remove w_obj; remove s_obj;|
  6240. \endlines
  6241. (We could even |alias| a new property |white_to| to be |n_to|, and then
  6242. enter map directions in the source code using Mayan property names.)
  6243. As a fine point of style, turquoise ({\it yax}) is the world colour for
  6244. `here', so add a grammar line to make this cause a ``look'':
  6245. \beginlines
  6246. |Verb "turquoise" "yax" * -> Look;|
  6247. \endlines}
  6248.  
  6249. \ansno5:
  6250. {^^{reflecting the map}\beginlines
  6251. |[ SwapDirs o1 o2 x;|
  6252. |  x=o1.door_dir; o1.door_dir=o2.door_dir; o2.door_dir=x; ];|
  6253. |[ ReflectWorld;|
  6254. |  SwapDirs(e_obj,w_obj); SwapDirs(ne_obj,nw_obj); SwapDirs(se_obj,sw_obj);|
  6255. |];|
  6256. \endlines}
  6257.  
  6258. \ansno6:
  6259. {This is a prime candidate for using ^{variable strings}
  6260. ^|@nn|, a topic properly covered in the {\sl Inform Technical Manual},
  6261. but briefly: at the head of the source, define
  6262. \beginlines
  6263. |Lowstring east_str "east"; Lowstring west_str "west";|
  6264. \endlines^^|Lowstring|^^|String|
  6265. and then add two more routines to the game,
  6266. \beginlines
  6267. |[ NormalWorld; String 0 #east_str; String 1 #west_str; ];|
  6268. |[ ReversedWorld; String 0 #west_str; String 1 #east_str; ];|
  6269. \endlines
  6270. where |NormalWorld| is called in |Initialise| or to go back to
  6271. normal, and |ReversedWorld| when the reflection happens.  Write
  6272. |@00| in place of |east| in any double-quoted printable string,
  6273. and similarly |@01| for |west|.  It will be printed as whichever
  6274. is currently set.  (Inform provides up to 32 such variable strings.)}
  6275.  
  6276. \ansno7:
  6277. {Declare a fake action called, say, |OpenUp|.  Then:
  6278. \beginlines
  6279. |Object medicine "guaranteed child-proof medicine bottle" cupboard|
  6280. |  with name "medicine" "bottle",|
  6281. |       description "~Antidote only: no preventative effect.~",|
  6282. |       before|
  6283. |       [;  Open, Unlock: "It's adult-proof too.";|
  6284. |           Openup: give self open ~locked; "The bottle cracks open!";|
  6285. |       ],|
  6286. |  has  container openable locked;|
  6287. \endlines
  6288. Any other code in the game can execute |<OpenUp medicine>| to crack open
  6289. the bottle.}
  6290.  
  6291. \ansno8:
  6292. {\beginlines
  6293. |Nearby glass_box "glass box with a lid"|
  6294. |  with name "glass" "box" "with" "lid"|
  6295. |  has  container transparent openable open;|
  6296. |Nearby steel_box "steel box with a lid"|
  6297. |  with name "steel" "box" "with" "lid"|
  6298. |  has  container openable open;|
  6299. \endlines}
  6300.  
  6301. \ansno9:
  6302. {^^{toothed bag}
  6303. \beginlines
  6304. |Object bag "toothed bag" room|
  6305. |  with name "toothed" "bag",|
  6306. |       description "A capacious bag with a toothed mouth.",|
  6307. |       before|
  6308. |       [; LetGo: "The bag defiantly bites itself \|
  6309. |                  shut on your hand until you desist.";|
  6310. |          Close: "The bag resists all attempts to close it.";|
  6311. |       ],|
  6312. |       after|
  6313. |       [; Receive:|
  6314. |                 print "The bag wriggles hideously as it swallows ";|
  6315. |                 DefArt(inp1); ".";|
  6316. |       ],|
  6317. |  has  container open;|
  6318. \endlines}
  6319.  
  6320. \ansno10:
  6321. {\beginlines^^{television set}
  6322. |Object television "portable television set" lounge|
  6323. |  with name "tv" "television" "set" "portable",|
  6324. |       before|
  6325. |       [;  SwitchOn: <<SwitchOn power_button>>;|
  6326. |           SwitchOff: <<SwitchOff power_button>>;|
  6327. |           Examine: <<Examine screen>>;|
  6328. |       ],|
  6329. |  has  transparent;|
  6330. |Nearby power_button "power button"|
  6331. |  with name "power" "button" "switch",|
  6332. |       after|
  6333. |       [;  SwitchOn, SwitchOff: <<Examine screen>>;|
  6334. |       ],|
  6335. |  has  switchable;|
  6336. |Nearby screen "television screen"|
  6337. |  with name "screen",|
  6338. |       before|
  6339. |       [;  Examine: if (power_button hasnt on) "The screen is black.";|
  6340. |               "The screen writhes with a strange Japanese cartoon.";|
  6341. |       ];|
  6342. \endlines}
  6343.  
  6344. \ansno11:
  6345. {Change the car's |before| to\beginlines
  6346. |    before|
  6347. |    [; Go: if (noun==d_obj or u_obj)|
  6348. |           {   print "(The car will never get over those stairs.)^";|
  6349. |               rfalse;|
  6350. |           }|
  6351. |           if (car has on) "Brmm!  Brmm!";|
  6352. |           print "(The ignition is off at the moment.)^";|
  6353. |    ],|
  6354. \endlines^^{little red car}}
  6355.  
  6356. \ansno12:
  6357. {The common man's {\it wayhel} was a lowly mouse.  Since we think
  6358. much more highly of the player:
  6359. \beginlines
  6360. |Object hog "Warthog" Caldera|
  6361. |  with name "wart" "hog" "warthog", description "Muddy and grunting.",|
  6362. |       number 0,|
  6363. |       initial "A warthog snuffles and grunts about in the ash.",|
  6364. |       before|
  6365. |       [; if (player==self && action~=##Go or ##Look or ##Examine)|
  6366. |              "Warthogs can't do anything as tricky as that!";|
  6367. |       ],|
  6368. |  has  animate proper;|
  6369. \endlines^^{warthog}^^{nagual}
  6370. and we just |ChangePlayer(warthog);|.  Note that this |before| rule is
  6371. carefully written only to affect actions of the player-as-warthog.
  6372. If the player-as-human should find and try to ``take warthog'', this
  6373. |before| routine won't interfere.}
  6374.  
  6375. \ansno13:
  6376. {Because |CDefArt(obj)| is a function call which, as it happens,
  6377. returns the value true, or 1 (not that this signifies anything), and
  6378. |print| thinks it is printing out a number.}
  6379.  
  6380. \ansno14:
  6381. {This is a crude implementation, for brevity (the real Zork I
  6382. thief has an enormous stock of attached messages).^^{thief in `Zork I'}
  6383. \beginlines
  6384. |Object thief "thief" Danger_Zone|
  6385. |  with name "thief",|
  6386. |       each_turn "^The thief growls menacingly.",|
  6387. |       daemon|
  6388. |       [ i p j n k;|
  6389. |           if (random(3)~=1) rfalse;|
  6390. |           p=parent(thief);|
  6391. |           objectloop (i in compass)|
  6392. |           {   j=p.(i.door_dir);|
  6393. |               if (j>player && j<=top_object && j hasnt door) n++;|
  6394. |           }|
  6395. |           if (n==0) rfalse;|
  6396. |           k=random(n); n=0;|
  6397. |           objectloop (i in compass)|
  6398. |           {   j=p.(i.door_dir);|
  6399. |               if (j>player && j<=top_object && j hasnt door) n++;|
  6400. |               if (n==k)|
  6401. |               {   move self to j;|
  6402. |                   if (p==location) "^The thief stalks away!";|
  6403. |                   if (j==location) "^The thief stalks in!";|
  6404. |                   rfalse;|
  6405. |               }|
  6406. |           }|
  6407. |       ];|
  6408. \endlines
  6409. This thief walks at random and cannot pass through doors, bridges and the like
  6410. (because these may be locked or have rules attached); it's only a first
  6411. approximation, and in a good game one should occasionally see the thief do
  6412. something surprising, such as open a secret door.}
  6413.  
  6414. \ansno15:
  6415. {First define a new property for object weight:^^{weights}
  6416. \beginlines
  6417. |Property weight 10;|
  6418. \endlines
  6419. (10 being an average sort of weight).  Containers weigh more when
  6420. they hold things, so we will need:
  6421. \beginlines
  6422. |[ WeightOf obj t i;|
  6423. |   t = obj.weight;|
  6424. |   objectloop (i in obj) t=t+WeightOf(i);|
  6425. |   return t;|
  6426. |];|
  6427. \endlines
  6428. Now for the daemon which monitors the player's fatigue:^^{fatigue daemon}
  6429. \beginlines
  6430. |Object weigher "weigher"|
  6431. |  with number 500,|
  6432. |       time_left 5,|
  6433. |       daemon|
  6434. |       [ w s b bw;|
  6435. |            w=WeightOf(player)-100-player.weight;|
  6436. |            s=self.number; s=s-w; if (s<0) s=0; if (s>500) s=500;|
  6437. |            self.number = s;|
  6438. |            if (s==0)|
  6439. |            {   bw=-1;|
  6440. |                objectloop(b in player)|
  6441. |                    if (WeightOf(b)>bw) { bw=WeightOf(b); w=b; }|
  6442. |                print "^Exhausted with carrying so much, you decide \|
  6443. |                    to discard "; DefArt(w); print ": "; <<Drop w>>;|
  6444. |            }|
  6445. |            w=s/100; if (w==self.time_left) rfalse;|
  6446. |            if (w==3) print "^You are feeling a little tired.^";|
  6447. |            if (w==2) print "^You possessions are weighing you down.^";|
  6448. |            if (w==1) print "^Carrying so much weight is wearing you out.^";|
  6449. |            self.time_left = w;|
  6450. |       ];|
  6451. \endlines
  6452. Notice that items are actually dropped with |Drop| actions: one of them
  6453. might be, say, a wild boar, which would bolt away into the forest when
  6454. released.  The daemon tries to drop the heaviest item.  (Obviously a little
  6455. improvement would be needed if the game contained, say, an un-droppable
  6456. but very heavy ball and chain.)  Now the daemon is going to run every turn
  6457. forever, but needs to be started: so put |StartDaemon(weigher);| into the
  6458. game's |Initialise| routine.}
  6459. \medskip
  6460.  
  6461. \ansno16:
  6462. {Either set a daemon to watch for |the_time| suddenly dropping, or
  6463. put such a watch in the game's |TimePasses| routine.}
  6464.  
  6465. \ansno17:
  6466. {Because you don't know what order daemons will run in.  A
  6467. `fatigue' daemon which makes the player drop something might come
  6468. after the `mid-air' daemon has run for this turn.  Whereas |each_turn|
  6469. happens after daemons and timers have run their course, and can fairly
  6470. assume no further movements will take place this
  6471. turn.^^{daemon running order}}
  6472.  
  6473. \ansno18:
  6474. {It would have to provide its own code to keep track of time,
  6475. and it can do this by providing a |TimePasses()| routine.  Providing
  6476. ``time'' or even ``date'' verbs to tell the player would also be a
  6477. good idea.}
  6478.  
  6479. \ansno19:
  6480. {^^{footnotes}
  6481. \beginlines
  6482. |Constant MAX_FOOTNOTES 10;|
  6483. |global footnotes_seen data MAX_FOOTNOTES;|
  6484. |global footnote_count;|
  6485. |[ Note n i pn;|
  6486. |    for (i=0:i<footnote_count:i++)|
  6487. |        if (n==footnotes_seen->i) pn=i;|
  6488. |    if (footnote_count==MAX_FOOTNOTES) "** MAX_FOOTNOTES exceeded! **";|
  6489. |    if (pn==0) { pn=footnote_count++; footnotes_seen->pn=n; }|
  6490. |    print " [",pn+1,"]";|
  6491. |];|
  6492. |[ FootnoteSub n;|
  6493. |    if (noun>footnote_count)|
  6494. |    {   print "No footnote [",noun,"] has been mentioned.^"; rtrue; }|
  6495. |    if (noun==0) "Footnotes count upward from 1.";|
  6496. |    n=footnotes_seen->(noun-1);|
  6497. |    print "[",noun,"]  ";|
  6498. |    if (n==0) "This is a footnote.";|
  6499. |    if (n==1) "D.G.REG.F.D is inscribed around English coins.";|
  6500. |    if (n==2) "~Jackdaws love my big sphinx of quartz~, for example.";|
  6501. |];|
  6502. ||
  6503. |Verb "footnote" "note" * number              -> Footnote;|
  6504. \endlines
  6505. And then call, for instance, |Note(1);| to refer in the game to
  6506. the ``English coins'' footnote.}
  6507.  
  6508. \ansno20:
  6509. {Because the parser might go on to reject the line it's working on:
  6510. for instance, if the player typed ``inventory splurge'' then the message
  6511. ``Shazam!'' followed by a parser complaint will be somewhat unedifying.}
  6512.  
  6513. \ansno21:
  6514. {Here goes: we could implement the buttons with five
  6515. separate objects, essentially duplicates of each other.  (And by using a
  6516. class definition, this wouldn't look too bad.)  But if there were
  6517. 500 slides this would be less reasonable.^^{spaceship control panel}
  6518. \beginlines
  6519. |[ ASlide w n;|
  6520. |   if (location~=Machine_Room)            !  Slides only make sense in|
  6521. |       return -1;                         !  the Machine Room|
  6522. |   w=NextWord();|
  6523. |   if (w=='slide') w=NextWord();|
  6524. |   n=0;|
  6525. |   if (w=='first' or 'one')   n=1;|
  6526. |   if (w=='second' or 'two')  n=2;|
  6527. |   if (w=='third' or 'three') n=3;|
  6528. |   if (w=='fourth' or 'four') n=4;|
  6529. |   if (w=='fifth' or 'five')  n=5;|
  6530. |   if (n==0) return -1;                   !  Failure!|
  6531. |   w=NextWord();|
  6532. |   if (w~='slide') wn--;                  !  Move word counter back to|
  6533. |                                          !  first misunderstood word|
  6534. |   parsed_number=n;|
  6535. |   return 1;                              !  Success!|
  6536. |];|
  6537. ||
  6538. |Global slide_settings data 10;            !  Ten bytes of data to hold|
  6539. |                                          !  five words for the settings|
  6540. |                                          !  (all initially zero)|
  6541. ||
  6542. |!  An interesting point here is that "noun" and "second" contain the|
  6543. |!  appropriate numbers, and not objects: this all happens automatically|
  6544. ||
  6545. |[ SetSlideSub;|
  6546. |   slide_settings-->(noun-1) = second;|
  6547. |   print_ret "You set slide number ", noun,|
  6548. |             " to the value ", second, ".";|
  6549. |];|
  6550. ||
  6551. |[ XSlideSub;|
  6552. |   print_ret "Slide number ", noun, " currently stands at ",|
  6553. |       slide_settings-->(noun-1), ".";|
  6554. |];|
  6555. ||
  6556. |Extend "set" first|
  6557. |           * ASlide "to" number                  -> SetSlide;|
  6558. |Extend "push" first|
  6559. |           * ASlide "to" number                  -> SetSlide;|
  6560. |Extend "examine" first|
  6561. |           * ASlide                              -> XSlide;|
  6562. \endlines}
  6563.  
  6564. \ansno22:
  6565. {^^{parsing quoted strings}
  6566. The ^{blackboard} code in ^{`Toyshop'} contains just such a routine:
  6567. \beginlines
  6568. |Global from_char; Global to_char;|
  6569. |[ QuotedText i j f;|
  6570. |   i = parse->((++wn)*4-3);|
  6571. |   if (buffer->i=='"')|
  6572. |   {   for (j=i+1:j<=(buffer->1)+1:j++)|
  6573. |           if (buffer->j=='"') f=j;|
  6574. |       if (f==0) return -1;|
  6575. |       from_char = i+1; to_char=f-1;|
  6576. |       if (from_char>to_char) return -1;|
  6577. |       while (f> (parse->(wn*4-3))) wn++; wn++;|
  6578. |       return 1;|
  6579. |   }|
  6580. |   return -1;|
  6581. |];|
  6582. \endlines^^{quoted text}
  6583. Note that in the case of success, the word marker |wn| is moved beyond the
  6584. last word accepted (since the Z-machine automatically tokenises
  6585. a double-quote as a single word).  The routine then tells the parser it
  6586. has parsed a number, which is a white lie.  What it actually does is to
  6587. record the byte positions where the quoted text starts and finishes in
  6588. the raw text |buffer| so that an action routine can easily extract the
  6589. text and use it later.  (Note that |""| with no text inside is not
  6590. matched by this routine but only because the last |if| statement throws
  6591. out that one case.)^^{double-quote}^^{tokenisation}}
  6592.  
  6593. \ansno23:
  6594. {^^{named rooms}
  6595. Define two properties:
  6596. \beginlines
  6597. |Property place_name;|
  6598. |Property long to_places;|
  6599. \endlines
  6600. The scheme will work like this: a named room should have the |place_name|
  6601. property set to a single dictionary word; say, the Bedquilt cave could
  6602. be called |'bedquilt'|.  Then in any room, a list of those other rooms
  6603. which can be moved to in this way should appear in the |to_places| entry.
  6604. For instance,
  6605. \beginlines
  6606. |to_places Bedquilt Slab_Room Twopit_Room;|
  6607. \endlines
  6608. Now the code: see if a not-understood verb is a place name of a nearby room,
  6609. and if so store that room's object number in |goto_room|, converting
  6610. the verb to a dummy.
  6611. \beginlines
  6612. |Global goto_room = 0;|
  6613. |[ UnknownVerb word p i;|
  6614. |    p = location.&to_places; if (p==0) rfalse;|
  6615. |    for (i=0:(2*i)<location.#to_places:i++)|
  6616. |        if (word==(p-->i).place_name)|
  6617. |        {   goto_room = p-->i; return 'go#room';|
  6618. |        }|
  6619. |    rfalse;|
  6620. |];|
  6621. |[ PrintVerb word;|
  6622. |    if (word=='go#room')|
  6623. |    { print "go to "; PrintShortName(goto_room); rtrue; }|
  6624. |    rfalse;|
  6625. |];|
  6626. \endlines
  6627. (The supplied |PrintVerb| is icing on the cake: so the parser can
  6628. say something like ``I only understood you as far as wanting to go to
  6629. Bedquilt.'' if need be.)  It remains only to put in code
  6630. and grammar for the ^{dummy verb}:
  6631. \beginlines
  6632. |[ GoRoomSub;|
  6633. |    if (goto_room hasnt visited) "But you have never been there.";|
  6634. |    PlayerTo(goto_room);|
  6635. |];|
  6636. |Verb "go#room"  *                                -> GoRoom;|
  6637. \endlines
  6638. Note that if you don't know the way, you can't go there!  A purist might
  6639. prefer instead to not recognise the name of an unvisited room, back at
  6640. the |UnknownVerb| stage, to avoid the player being able to deduce names
  6641. of nearby rooms from this `error message'.}
  6642.  
  6643. \ansno24:
  6644. {A slight refinement of such a ^{``purloin'' verb} is already defined
  6645. in the library (if the constant |DEBUG| is defined), so there's no need.
  6646. Here's how it could be done:
  6647. \beginlines
  6648. |[ Anything i;|
  6649. |  if (scope_stage==1) rfalse;|
  6650. |  if (scope_stage==2)|
  6651. |  {   for (i=1:i<=top_object:i++) PlaceInScope(i); rtrue; }|
  6652. |  "No such in game.";|
  6653. |];|
  6654. \endlines^^{token for `any object'}
  6655. (This disallows multiple matches for efficiency reasons - the parser has
  6656. enough work to do with such a huge scope definition as it is.)  Now
  6657. the token |scope=Anything| will match anything at all, even things like
  6658. the abstract concept of `east'.}
  6659.  
  6660. \ansno25:
  6661. {For good measure, we'll combine this with the previous rule
  6662. about |moved| objects being in scope in the dark.  The following
  6663. can be inserted into the `Shell' game:^^{light switch}
  6664. \beginlines
  6665. |Object coal "dull coal" Blank_Room|
  6666. |  with name "dull" "coal";|
  6667. ||
  6668. |Object Dark_Room "Dark Room"|
  6669. |  with description "An empty room with a west exit.",|
  6670. |       each_turn|
  6671. |       [; if (self has general) self.each_turn=0;|
  6672. |          else "^You hear the breathing of a dwarf.";|
  6673. |       ],|
  6674. |       w_to Blank_Room;|
  6675. ||
  6676. |Nearby light_switch "light switch"|
  6677. |  with name "light" "switch",|
  6678. |       initial "On one wall is the light switch.",|
  6679. |       after|
  6680. |       [; SwitchOn: give Dark_Room light;|
  6681. |          SwitchOff: give Dark_Room ~light;|
  6682. |       ],|
  6683. |  has  switchable static;|
  6684. ||
  6685. |Nearby diamond "shiny diamond"|
  6686. |  with name "shiny" "diamond"|
  6687. |  has  scored;|
  6688. ||
  6689. |Nearby dwarf "dwarf"|
  6690. |  with name "voice" "dwarf",|
  6691. |       life|
  6692. |       [; Order: if (action==##SwitchOn && noun==light_switch)|
  6693. |                 {   give Dark_Room light general;|
  6694. |                     give light_switch on; "~Right you are, squire.~";|
  6695. |                 }|
  6696. |       ],|
  6697. |  has  animate;     |
  6698. ||
  6699. |[ InScope person i;|
  6700. |  if (parent(person)==Dark_Room)|
  6701. |  {   if (person==dwarf || Dark_Room has general)|
  6702. |          PlaceInScope(light_switch);|
  6703. |  }|
  6704. |  if (person==player && location==thedark)|
  6705. |      objectloop (i near player)|
  6706. |          if (i has moved || i==dwarf)|
  6707. |              PlaceInScope(i);|
  6708. |  rfalse;|
  6709. |];|
  6710. \endlines
  6711. Note that the routine puts the light switch in scope for the dwarf -
  6712. if it didn't, the dwarf would not be able to understand
  6713. ``dwarf, turn light on", and that was the whole point.}
  6714.  
  6715. \ansno26:
  6716. {Just test if |HasLightSource(gift)==1|.}
  6717.  
  6718. \ansno27:
  6719. {\beginlines
  6720. |[ DoubleInvSub i count1 count2;|
  6721. |  print "You are carrying ";|
  6722. |  objectloop (i in player)|
  6723. |  {   if (i hasnt worn) { give i workflag; count1++; }|
  6724. |      else { give i ~workflag; count2++; }|
  6725. |  }|
  6726. |  if (count1==0) print "nothing.";|
  6727. |  else|
  6728. |  WriteListFrom(child(player),|
  6729. |      FULLINV_BIT + ENGLISH_BIT + RECURSE_BIT + WORKFLAG_BIT);|
  6730. ||
  6731. |  if (count2==0) ".";|
  6732. |  print ".  In addition, you are wearing ";|
  6733. |  objectloop (i in player)|
  6734. |  {   if (i hasnt worn) give i ~workflag; else give i workflag;|
  6735. |  }|
  6736. |  WriteListFrom(child(player),|
  6737. |      ENGLISH_BIT + RECURSE_BIT + WORKFLAG_BIT);|
  6738. |  ".";|
  6739. |];|
  6740. \endlines^^{double inventory}}
  6741.  
  6742. \ansno28:
  6743.  {\beginlines
  6744. |Global c_warned = 0;|
  6745. |Class  cherub_class|
  6746. |  with parse_name|
  6747. |       [ i j flag;|
  6748. |         for (flag=1:flag==1:flag=0)|
  6749. |         {   j=NextWord();|
  6750. |             if (j=='cherub' or j==self.name) flag=1;|
  6751. |             if (j=='cherubs' && c_warned==0)|
  6752. |             {   c_warned=1;|
  6753. |                 parser_action=##PluralFound; flag=1;|
  6754. | print "(I'll let this go once, but the plural of cherub is cherubim.)^";|
  6755. |             }|
  6756. |             if (j=='cherubim')|
  6757. |             {   parser_action=##PluralFound; flag=1; }|
  6758. |             i++;|
  6759. |         }|
  6760. |         return i-1;|
  6761. |       ];|
  6762. \endlines
  6763. Then again, Shakespeare even writes ``cherubins'' in {\sl Twelfth Night},
  6764. so who are we to censure?^^{cherubim}^^{William Shakespeare}}
  6765.  
  6766. \ansno29:
  6767. {First put the directive |Replace DrawStatusLine;| before including
  6768. the library.  Then add the following routine anywhere after |treasures_found|,
  6769. an `Advent' variable, is defined:
  6770. \beginlines
  6771. |[ DrawStatusLine;|
  6772. |   @split_window 1; @set_window 1; @set_cursor 1 1; style reverse;|
  6773. |   spaces (0->33)-1;|
  6774. |   @set_cursor 1 2;  PrintShortName(location);|
  6775. |   if (treasures_found > 0)|
  6776. |   {   @set_cursor 1 50; print "Treasure: ", treasures_found;|
  6777. |   }|
  6778. |   @set_cursor 1 1; style roman; @set_window 0;|
  6779. |];|
  6780. \endlines}
  6781.  
  6782. \ansno30:
  6783. {Note the magic line of assembly code here, which only works for
  6784. Advanced games:
  6785. \beginlines^^{``Invisiclues''}
  6786. |[ GiveHint hint keypress;|
  6787. |  print_paddr hint; new_line; new_line;|
  6788. |  @read_char 1 0 0 keypress;|
  6789. |  if (keypress == 'H' or 'h') rfalse;|
  6790. |  rtrue;|
  6791. |];|
  6792. \endlines
  6793. And a typical menu item using it:
  6794. \beginlines
  6795. | if (menu_item==1)|
  6796. | {   print "(Press ENTER to return to menu, or H for another hint.)^^";|
  6797. |     if (GiveHint("(1/3)  What kind of bird is it, exactly?")==1) return 2;|
  6798. |     if (GiveHint("(2/3)  Magpies are attracted by shiny items.")==1) return 2;|
  6799. |     "(3/3)  Wave at the magpie with the kitchen foil.";|
  6800. | }|
  6801. \endlines}
  6802.  
  6803. \ansno31:
  6804. {|Primes(100)|, where:\beginlines
  6805. |[ Primes i j k l;|
  6806. |  for (j=2:j<=i:j++)|
  6807. |  {   print j, " : "; l=j;|
  6808. |      while (l > 1)|
  6809. |      for (k=2:k<=l:k++)|
  6810. |          if (l%k == 0) { l=l/k; print k, " "; break; }|
  6811. |      new_line;|
  6812. |  }|
  6813. |];|
  6814. \endlines^^{prime factorisations}
  6815. (which was the first algorithm ever compiled by Inform).}
  6816. \tenpoint
  6817. \vfill\eject
  6818. \section{A7}{Index}\bigskip\ninepoint
  6819. \beginindex
  6820. |*|, 61, 69.
  6821. |++|, 84.
  6822. |--|, 84.
  6823. |-->|, 68.
  6824. |->|, 38, 68.
  6825. |@@|, 69.
  6826.  
  6827. abbreviations, 62, 89.
  6828. |absent|, 74.
  6829. ``abstract'' verb, 60.
  6830. `Acheton', 3.
  6831. |Achieved(task)|, 58.
  6832. action groups, 19.
  6833. action numbers, 19.
  6834. actions, 7, 19, 73.
  6835. ``actions'' verb, 8, 60.
  6836. |actor|, 47.
  6837. |additive|, 11, 33.
  6838. addresses, 8.
  6839. Advanced games, 8, 12, 14, 61, 65, 65, 87, 89.
  6840. `Advent', 31, 33, 34, 43, 63, 89, 90.
  6841. |after|, 5, 17, 20, 76.
  6842. |AfterLife|, 31, 78.
  6843. |alias|, 10, 11, 83.
  6844. |AllowPushDir()|, 27.
  6845. almond poisoning, 6.
  6846. |Amusing|, 78.
  6847. |AMUSING PROVIDED|, 58.
  6848. |animate|, 74.
  6849. |Answer|, 28.
  6850. appallingly convenient verb, 40.
  6851. archaeological dig, 36.
  6852. ``Area 400", 54.
  6853. |aread|, 66.
  6854. Aristotle, 9.
  6855. arithmetic operators, 70.
  6856. arrays, 68.
  6857. |article|, 31, 76.
  6858. |Ask|, 28.
  6859. asking questions, 45.
  6860. assembler errors, 87.
  6861. assembly language, 65.
  6862. assignments, 70.
  6863. |Attack|, 27.
  6864. |Attribute|, 10.
  6865. attributes, 5, 10.
  6866. attributes in library, 74.
  6867. audibility, 35.
  6868. |autosearch|, 76.
  6869.  
  6870. background daemon, 34.
  6871. backslash, 67, 69.
  6872. bag of six coins, 55.
  6873. `Balances', 42, 56.
  6874. banana, 39.
  6875. batteries, 25.
  6876. Bedquilt Room, 21.
  6877. |beep|, 66.
  6878. |before|, 6, 76.
  6879. binary, 69.
  6880. blackboard, 97.
  6881. blocks of code, 72.
  6882. |Blorple|, 20.
  6883. boldface, 65.
  6884. bolted cupboard, 23.
  6885. |box|, 63.
  6886. brace mismatch, 85.
  6887. braces, 72.
  6888. brain transference machine, 30.
  6889. brass lantern, 25.
  6890. |break|, 73.
  6891. |buffer mode|, 66.
  6892. built-in functions, 71.
  6893. byte address, 8.
  6894.  
  6895. C. P. Snow, 48.
  6896. C. S. Lewis, 34, 74.
  6897. Cambridge University, 3.
  6898. |cant go|, 16, 76.
  6899. |capacity|, 22, 30, 77.
  6900. |CDefArt(obj)|, 31.
  6901. ``ceiling'', 74.
  6902. chair, 29.
  6903. |ChangePlayer|, 30.
  6904. changing scope, 47.
  6905. changing the player, 30.
  6906. character graphic, 63.
  6907. cherubim, 57, 100.
  6908. |child|, 9, 60.
  6909. |children|, 60.
  6910. |class|, 14, 14, 33.
  6911. class errors, 83.
  6912. classes, 32.
  6913. clearing the screen, 66.
  6914. closing credits, 58.
  6915. |clothing|, 74.
  6916. clues, 64.
  6917. `Colossal Cave', 43.
  6918. command line syntax, 88.
  6919. comments, 67.
  6920. `companion volumes', 2.
  6921. compiler switches, 88.
  6922. |concealed|, 45, 74.
  6923. conditional compilation, 67, 84.
  6924. conditions, 70.
  6925. Connie Booth, 63.
  6926. constants, 69.
  6927. |container|, 22, 75.
  6928. control constructs, 72.
  6929. copyright, 3.
  6930. crashing the interpreter, 60.
  6931. creature token, 39.
  6932. crowns, 56.
  6933. crystal chandelier, 15.
  6934. `Curses', 12, 90.
  6935. cursor keys, 66.
  6936.  
  6937. |daemon|, 34, 77.
  6938. daemon running order, 95.
  6939. daemons, 34.
  6940. darkness, 45.
  6941. |DarkToDark|, 50, 78.
  6942. |data|, 68.
  6943. David M. Baggett, 31, 40.
  6944. David Seal, 3.
  6945. |deadflag|, 6, 31.
  6946. |DeathMessage|, 31, 78.
  6947. |DEBUG|, 8, 59.
  6948. `debugging code', 61.
  6949. ``debugging information'' file, 89.
  6950. debugging verbs, 59.
  6951. |DefArt(obj)|, 31.
  6952. default value of properties, 11.
  6953. definite article, 32.
  6954. definition of darkness, 48.
  6955. dentist's chair, 26.
  6956. depressed philosophers, 29.
  6957. |describe|, 13, 77.
  6958. |description|, 77.
  6959. dictionary errors, 85.
  6960. dictionary resolution, 62.
  6961. dictionary words, 77.
  6962. |direction|, 75.
  6963. direction objects, 17, 74, 78, 91.
  6964. direction properties, 78.
  6965. directions, 16, 45.
  6966. directive, 10.
  6967. directives, 67.
  6968. dirty tricks, 65.
  6969. division by zero, 70.
  6970. |DoMenu|, 64.
  6971. Don Woods, 3.
  6972. Donna Tartt, 18.
  6973. |door|, 23, 75.
  6974. |door dir|, 23, 24, 77.
  6975. |door to|, 23, 77.
  6976. Dorothy Parker, 64.
  6977. double inventory, 52, 100.
  6978. double spacing, 89.
  6979. double-quote, 97.
  6980. dramatic effects, 48.
  6981. drawings, 63.
  6982. `drunk player object', 30.
  6983. dummy verb, 98.
  6984.  
  6985. |each turn|, 35, 77.
  6986. earshot, 35.
  6987. `economy' mode, 89.
  6988. |edible|, 75.
  6989. |elder|, 10.
  6990. |eldest|, 10.
  6991. embedded routines, 13, 69.
  6992. `Enchanter', 23.
  6993. |EnglishNumber(x)|, 79.
  6994. |Enter|, 24.
  6995. |enterable|, 26, 75.
  6996. entry points, 78.
  6997. epigrams, 63.
  6998. |erase window|, 66.
  6999. error messages, 81.
  7000. |et flag|, 35.
  7001. exotic forms of death, 31.
  7002. expression errors, 85.
  7003. expressions, 70.
  7004. |Extend|, 42.
  7005.  
  7006. |Fake Action|, 21.
  7007. fake actions, 19, 22, 29, 56.
  7008. fatal errors, 81.
  7009. fatigue daemon, 95.
  7010. |female|, 75.
  7011. file format, 67.
  7012. |first|, 42.
  7013. flags, 10.
  7014. flexible verbs, 43.
  7015. `floating object', 74.
  7016. ``floor'', 74.
  7017. fluorescent jellyfish, 50.
  7018. `focus' of game, 30.
  7019. |font|, 63.
  7020. footnotes, 40, 96.
  7021. |for|, 73.
  7022. foreign character sets, 69.
  7023. |found in|, 12, 18, 77.
  7024. Frankenstein, 30.
  7025. ``free'' verb, 40.
  7026. function arguments, 69.
  7027. function keys, 66.
  7028. fuses, 35.
  7029.  
  7030. G. K. Chesterton, 31.
  7031. |GamePostRoutine|, 21, 78.
  7032. |GamePreRoutine|, 21, 78.
  7033. |general|, 75.
  7034. George Bernard Shaw, 44.
  7035. |give|, 10, 28.
  7036. glass box, 22.
  7037. |Global|, 68.
  7038. global variables, 83.
  7039. |Go|, 17, 26.
  7040. ``goto'' verb, 60.
  7041. Graham Nelson, 3.
  7042. Grammar, 7.
  7043. |Grammar|, 4.
  7044. grammar lines, 37.
  7045. grammar tokens, 38.
  7046. grammatical errors, 83.
  7047. green cone, 4.
  7048. grues, 45.
  7049.  
  7050. hacker and urchin, 29.
  7051. hanging elses, 72.
  7052. hangover, 14.
  7053. |has|, 10, 12.
  7054. `has light', 49.
  7055. hash character, 67.
  7056. |HasLightSource(object)|, 49.
  7057. |Headline|, 80.
  7058. held token, 39.
  7059. `Hello Cruel World', 4.
  7060. hexadecimal, 11.
  7061.  
  7062. |if|, 72.
  7063. in scope, 44.
  7064. |InDefArt(obj)|, 31.
  7065. indefinite article, 31.
  7066. |indirect|, 60.
  7067. `indistinguishable', 55.
  7068. Infact, 60.
  7069. Infix, 60, 89.
  7070. Infocom, Inc., 3.
  7071. Inform 5.2, 3.
  7072. InfoTaskForce, 65.
  7073. inheritance, 14, 33.
  7074. |initial|, 5, 68, 77.
  7075. initial possessions, 29.
  7076. |Initialise|, 4, 29, 29, 36, 78, 78.
  7077. |initstr|, 68, 68.
  7078. |InScope|, 78.
  7079. |Insert|, 22.
  7080. internal errors, 87.
  7081. interpreter, 8.
  7082. interpreters, 65.
  7083. |invent|, 52, 77.
  7084. inventories, 52.
  7085. |inventory stage|, 52.
  7086. ``Invisiclues'', 64, 101.
  7087. Ivan O. Ideas, 57.
  7088.  
  7089. James Shirley, 18.
  7090. Jean de la Bruy{\accent 18 e}re, 29.
  7091. John Christopher, 15.
  7092. John Cleese, 63.
  7093. John Donne, 15.
  7094. Jonathan Thackray, 3.
  7095. |jump|, 69.
  7096. ``junior astronaut", 79.
  7097.  
  7098. keyboard, 66.
  7099. |Kiss|, 27.
  7100.  
  7101. labels, 69.
  7102. large memory, 90.
  7103. |last|, 42.
  7104. |LetGo|, 22.
  7105. lexicon, 7.
  7106. library, 7.
  7107. library routines, 79.
  7108. |life|, 27, 77.
  7109. |light|, 10, 75.
  7110. light and dark, 48.
  7111. light switch, 47, 99.
  7112. limitations, 61.
  7113. line of sight, 35.
  7114. listing objects, 50.
  7115. little red car, 26, 94.
  7116. local variables, 68.
  7117. |location|, 30.
  7118. |lockable|, 75.
  7119. |locked|, 22, 75.
  7120. |long|, 11.
  7121. Long Count, 46.
  7122. |LookRoutine|, 78.
  7123. loop over every object, 73.
  7124. Louis MacNeice, 2.
  7125. low mist, 18.
  7126. low numbers in French, 41.
  7127. |Lowstring|, 92.
  7128. Ludwig Wittgenstein, 27, 37.
  7129.  
  7130. making actions, 21.
  7131. making attributes, 10.
  7132. making grammar, 21, 37.
  7133. making properties, 11.
  7134. map, 16, 23.
  7135. Marc Blank, 23, 26.
  7136. ``master catburglar", 79.
  7137. matchbook, 52.
  7138. Max Beerbohm, 44.
  7139. |MAX CARRIED|, 57.
  7140. |MAX SCORES|, 58.
  7141. |MAX TIMERS|, 35.
  7142. Mayan directions, 17, 91.
  7143. ``me'', 30.
  7144. medicine bottle, 21.
  7145. memory consumption, 90.
  7146. memory management, 89.
  7147. memory map, 8.
  7148. memory settings, 82, 90.
  7149. memory size, 62.
  7150. menu of text options, 64.
  7151. |meta|, 20, 43.
  7152. Michel de Montaigne, 27.
  7153. mid-air location, 36.
  7154. Moli{\accent 18 e}re, 37.
  7155. |move|, 9.
  7156. |moved|, 47, 75.
  7157. moving the player, 30.
  7158. multiexcept token, 39.
  7159. multiheld token, 39.
  7160. ``myself'', 30.
  7161.  
  7162. nagual, 31, 94.
  7163. |name|, 14, 14, 54, 77.
  7164. named rooms, 44, 98.
  7165. narrow inventory, 51.
  7166. |Nearby|, 13.
  7167. NetHack, 65.
  7168. |NewRoom|, 78.
  7169. |NextWord|, 41.
  7170. |@nn|, 92.
  7171. normal rules, 19, 74.
  7172. |nothing|, 10, 60.
  7173. |notify mode|, 59.
  7174. ``notify'' verb, 59.
  7175. noun token, 39.
  7176. |number|, 77.
  7177. |NUMBER TASKS|, 58.
  7178. number token, 39.
  7179. number-parsing, 41.
  7180. numbers, 8.
  7181.  
  7182. |Object|, 12.
  7183. object definitions, 12.
  7184. object errors, 83.
  7185. |OBJECT SCORE|, 58.
  7186. Object syntax, 14.
  7187. |objectloop|, 73.
  7188. objects, 9.
  7189. objects in library, 74.
  7190. `offers light', 49.
  7191. |OffersLight(object)|, 49.
  7192. ogre with limited patience, 35.
  7193. Oliver Goldsmith, 61.
  7194. |on|, 25, 75.
  7195. |open|, 22, 75.
  7196. |openable|, 22, 76.
  7197. |or|, 71.
  7198. |Order|, 28.
  7199. ``out'' verb, 26.
  7200. output streams, 66.
  7201. oyster, 21.
  7202.  
  7203. P. David Lebling, 22, 23, 26.
  7204. packed address, 8.
  7205. |parent|, 9, 60.
  7206. |parse name|, 54, 56, 77.
  7207. |parsed number|, 41.
  7208. |ParseNumber|, 41, 78.
  7209. parser, 37.
  7210. |Parser|, 4.
  7211. |parser one, parser two, parser action|, 56.
  7212. parser questions, 43.
  7213. parser speed, 83.
  7214. parser tracing and levels, 61.
  7215. |ParserError|, 48, 78.
  7216. parsing quoted strings, 44, 97.
  7217. passing messages, 21.
  7218. Pepper Room, 18.
  7219. perfectly sensible, 11.
  7220. Peter and Jane, 69.
  7221. pinfocom, 65.
  7222. |PlaceInScope|, 46.
  7223. plagiarism, 57.
  7224. plaster of paris, 27.
  7225. player's origin, 29.
  7226. |PlayerTo|, 30, 60.
  7227. |plural|, 55, 77.
  7228. plural objects, 55.
  7229. precedence, 33.
  7230. prime factorisations, 73, 101.
  7231. |print|, 17.
  7232. |print addr|, 60.
  7233. |print object|, 31, 60.
  7234. |print paddr|, 60.
  7235. printing commands, 71.
  7236. |PrintRank|, 58, 79.
  7237. |PrintShortName(obj)|, 31.
  7238. |PrintTaskName|, 79.
  7239. |PrintVerb|, 43, 79.
  7240. |proper|, 32, 76.
  7241. proper noun, 32.
  7242. properties, 5, 11.
  7243. properties in library, 76.
  7244. |Property|, 11.
  7245. proportional font, 63.
  7246. puff of garlic, 71.
  7247. ``purloin'' verb, 47, 60, 98.
  7248. |PushDir|, 27.
  7249.  
  7250. questions, 45.
  7251. questions (yes or no), 59.
  7252. quotations beautiful, 64.
  7253. quoted text, 97.
  7254. ``quotes off'' verb, 64.
  7255.  
  7256. radio, 35.
  7257. rainbows, 16.
  7258. |random|, 60.
  7259. |read char|, 66.
  7260. real time, 66.
  7261. |Receive|, 22.
  7262. reflecting the map, 17, 92.
  7263. release number, 67.
  7264. |Remove|, 22.
  7265. |replace|, 42, 59.
  7266. replacing grammar, 42.
  7267. resurrection, 31.
  7268. returning from routines, 72.
  7269. reusing attributes, 10.
  7270. reverse video, 65.
  7271. roman text, 65.
  7272. |ROOM SCORE|, 58.
  7273. routine errors, 84.
  7274. routine tracing, 61.
  7275. routines, 69.
  7276. ``routines'' verb, 60.
  7277. rucksack, 39.
  7278. run-time crashes, 60.
  7279. run-time format, 61.
  7280. running out of memory, 81.
  7281. rusty door, 23.
  7282.  
  7283. S\o ren Kierkegaard, 29.
  7284. |SACK OBJECT|, 57.
  7285. |scenery|, 16, 76.
  7286. scope, 44.
  7287. |scope stage|, 46.
  7288. score notification, 59.
  7289. ``score'' verb, 43.
  7290. |scored|, 76.
  7291. scoring systems, 58.
  7292. screen tricks, 65.
  7293. |Search|, 20.
  7294. searchlight, 25.
  7295. `see-through', 44.
  7296. |self|, 19.
  7297. |selfobj|, 73, 74.
  7298. serial number, 67.
  7299. |set cursor|, 66.
  7300. |set window|, 66.
  7301. |SetTime|, 36.
  7302. ``shazam'' verb, 43.
  7303. `Shell', 4.
  7304. |short name|, 53, 77.
  7305. |Show|, 28.
  7306. |sibling|, 9.
  7307. silver bars, 33.
  7308. Sloping Corridor, 16.
  7309. small array, 12.
  7310. small memory, 90.
  7311. ``snavig'' spell, 30.
  7312. sound effect, 66.
  7313. source-level debugger, 60.
  7314. |sp|, 68.
  7315. Space Invaders, 65.
  7316. spaceship control panel, 43, 96.
  7317. special effects, 63.
  7318. |special number|, 28.
  7319. special objects, 74.
  7320. special token, 39.
  7321. |special word|, 28.
  7322. `Spellbreaker cubes', 56.
  7323. `Spellbreaker', 20, 30.
  7324. |split window|, 65.
  7325. Square Room, 15.
  7326. stack pointer, 68.
  7327. Standard games, 8, 10, 12, 14, 61, 65, 87, 89.
  7328. |StartDaemon|, 34.
  7329. |StartTimer|, 35.
  7330. |static|, 24, 76.
  7331. statistics, 89.
  7332. status line, 60, 63.
  7333. |Statusline|, 36.
  7334. steel box, 22.
  7335. steel grate, 24.
  7336. |StopDaemon|, 34.
  7337. |StopTimer|, 35.
  7338. |Story|, 80.
  7339. story files, 2.
  7340. stream, 35.
  7341. |string|, 68, 92.
  7342. |style|, 65.
  7343. style of list, 50.
  7344. sullen snake, 28.
  7345. |supporter|, 22, 26, 76.
  7346. |sw var|, 13.
  7347. |switchable|, 25, 76.
  7348. switches (on command line), 88.
  7349. sword, 35.
  7350. symbol names, 82.
  7351. synonyms, 37.
  7352.  
  7353. T. S. Eliot, 53.
  7354. ``take'' verb, 37.
  7355. |talkable|, 76.
  7356. |task scores|, 58.
  7357. |TASKS PROVIDED|, 58.
  7358. tasty food, 13.
  7359. team of four adventurers, 30.
  7360. teleportation, 30.
  7361. television set, 23, 93.
  7362. Tera, 3.
  7363. text style, 65.
  7364. `The Legend Lives', 40.
  7365. The Prisoner, 26.
  7366. |the time|, 36.
  7367. |thedark|, 30, 74.
  7368. |TheSame|, 56.
  7369. thief in `Zork I', 34, 35, 94.
  7370. |ThrowAt|, 28, 29.
  7371. tidying-up operations, 34.
  7372. |time left|, 77.
  7373. time of day, 36.
  7374. |time out|, 35, 77.
  7375. time sequence, 36.
  7376. timed input, 66.
  7377. |TimePasses|, 79.
  7378. timers, 35.
  7379. ``timers'' verb, 60.
  7380. Timothy Anderson, 26.
  7381. toffee apple, 18.
  7382. token for `any object', 99.
  7383. tokenisation, 97.
  7384. tokens, 38.
  7385. toothed bag, 22, 93.
  7386. |top object|, 73.
  7387. `Toyshop', 34, 53, 97.
  7388. ``trace'' verb, 60.
  7389. tracing a routine, 61.
  7390. tracing routines, actions, daemons and timers, 60.
  7391. tracing the parser, 61.
  7392. transcript, 66.
  7393. |transparent|, 22, 23, 29, 76.
  7394. treasure class, 33.
  7395. tree of objects, 9.
  7396. ``tree'' verb, 60.
  7397. `Trinity', 17.
  7398. troll, 50.
  7399. |TryNumber|, 80.
  7400. two-way door, 24.
  7401. txd (disassembler), 60.
  7402. types (lack of), 11.
  7403.  
  7404. underlining, 65.
  7405. ``undo'' verb, 62, 65.
  7406. |UnknownVerb|, 43, 79.
  7407. urchin and hacker, 29.
  7408.  
  7409. valuable cake, 33.
  7410. variable strings, 92.
  7411. variables, 68.
  7412. vehicles, 26.
  7413. |Verb|, 37.
  7414. |VerbLib|, 4.
  7415. version 6, 62.
  7416. very last resort, 59.
  7417. |visited|, 76.
  7418. vocabulary size, 62.
  7419. VT100, 65.
  7420.  
  7421. W. H. Auden, 23.
  7422. W. S. Gilbert, 50.
  7423. walls, 74.
  7424. `wandering monsters', 34.
  7425. warnings, 87.
  7426. warthog, 94.
  7427. weights, 34, 95.
  7428. weird thing, 54.
  7429. ``what is a grue'', 45.
  7430. |when closed|, 24, 77.
  7431. |when off|, 77.
  7432. |when on|, 77.
  7433. |when open|, 24, 77.
  7434. wide inventory, 51.
  7435. William Shakespeare, 44, 100.
  7436. Willie Crowther, 3.
  7437. |with|, 12.
  7438. |with key|, 22, 77.
  7439. |wn|, 41.
  7440. woodpecker, 59.
  7441. |workflag|, 76.
  7442. world colours, 17, 91.
  7443. |worn|, 76.
  7444. |WriteListFrom|, 50.
  7445.  
  7446. ``xyzzy'' verb, 38.
  7447.  
  7448. |YesOrNo()|, 59.
  7449. |younger|, 10.
  7450. |youngest|, 10.
  7451.  
  7452. Z-machine, 8.
  7453. ``zero'', 41.
  7454. Zip, 60, 60, 65.
  7455. `Zork I', 34, 35.
  7456. `Zork', 8.
  7457. zterp, 65.
  7458. \endindex
  7459. \end
  7460. %  End of TeX source for the Inform Designer's Manual
  7461.  
  7462.