| |||||||||
Contents Back Forward |
| ||||||||
Even at present... we still know very little about how access to printed materials affects human behaviour. look up figure 18 in the engineering textbookis a difficult line for Inform to understand, because almost anything could appear in the first part: even its format depends on what the second part is. This kind of request, and more generally look up <any words here> in <the object>cause the Consult object action. Note that second is just zero: formally, there is no second noun attached to a Consult action. The object has to parse the <any words here> part itself, in a before rule for Consult. The following variables are set up to make this possible: consult_from holds the number of the first word in the <any...> clause; consult_words holds the number of words in the <any...> clause (at least 1). The words given are parsed using library routines like NextWord(), TryNumber(word-number) and so on: see Section 24 for full details. As usual, the before routine should return true if it has managed to deal with the action; returning false will make the library print "You discover nothing of interest in...''. Little hints are placed here and there in the 'Ruins', written in the glyphs of an ancient dialect of Mayan. Our explorer has, of course, come equipped with the latest and finest scholarship on the subject: Object dictionary "Waldeck's Mayan dictionary" with name "dictionary" "local" "guide" "book" "mayan" "waldeck" "waldeck^s", description "Compiled from the unreliable lithographs of the legendary raconteur and explorer ~Count~ Jean Frederic Maximilien Waldeck (1766??-1875), this guide contains what little is known of the glyphs used in the local ancient dialect.", before [ w1 w2 glyph other; Consult: if (consult_words>2) jump GlyphHelp; wn=consult_from; w1 = NextWord(); ! First word of subject w2 = NextWord(); ! Second word (if any) of subject if (consult_words==1 && w1=='glyph' or 'glyphs') jump GlyphHelp; ! We want to recognise both "glyph q1" and "q1 glyph": glyph=w1; other=w2; if (w1=='glyph') { glyph=w2; other=w1; } ! So now glyph holds the name, and other the other word if (consult_words==2 && other~='glyph') jump GlyphHelp; switch(glyph) { 'q1': "(This is one glyph you have memorised!)^^ Q1: ~sacred site~."; 'circle': "Circle: ~the Sun; also life, lifetime~."; ... default: "That glyph is so far unrecorded."; } ! All three of the ways the text can go wrong lead to ! this message being produced: .GlyphHelp; "Try ~look up <name of glyph> in book~."; ], has proper;Note that this understands any of the forms "q1'', "glyph q1'' or "q1 glyph'' but is careful to reject, for instance, "glyph q1 glyph''. (These aren't genuine Mayan glyphs, but some of the real ones have similar names, dating from when their syllabic equivalents weren't known: G8, the Lord of the Night, for instance.)
| |||||||||
EXERCISE 17: (link to the answer) | |||||||||
To mark the 500th anniversary of William Tyndale (the first
English translator of the New Testament), prepare an edition of the
four Gospels.
| |||||||||
Ordinarily, a request by the player to "read'' something is translated
into an Examine action. But the "read'' verb is defined independently
of the "examine'' verb in order to make it easy to separate the two
requests. For instance:
Attribute legible; ... Object textbook "textbook" with name "engineering" "textbook" "text" "book", description "What beautiful covers and spine!", before [; Consult, Read: "The pages are full of senseless equations."; ], has legible; ... [ ReadSub; <<Examine noun>>; ]; Extend "read" first * legible -> Read;
Note that "read" causes a Read action only for legible objects,
and otherwise causes Examine in the usual way. ReadSub is coded
as a translation to Examine as well, so that if a legible object
doesn't provide a Read rule then an Examine happens after all.
|
|
REFERENCES: | If you really need more elaborate topic-parsing (for, e.g., "look up <something> in the catalogue'', where any object name might appear) then extending the grammar for look may be less trouble. For a good implementation see 'Encyclopaedia Frobozzica', by Gareth Rees. |