| Chapter 21: Extensions |

| 21.13. Defining phrases in Inform 6

The phrases described in this documentation, such as "end the game in death", are all defined in the Standard Rules, and are for the most part defined not in terms of other I7 phrases but instead reduced to equivalents in I6. For instance:

> To end the game in death: (- deadflag=1; -).

The notation "(-" and "-)" indicates that what comes in between is I6 code. The minus sign is supposed to be a mnemonic for the decrease from 7 to 6: later we shall use "(+" and "+)" to go back up the other way, from 6 to 7.

When a phrase is defined as containing only a single command, and that command is defined using I6 - as here - it is compiled in-line. This means that the phrase "end the game in death" will always be translated as "deadflag=1;", rather than being translated into a call to a suitable function whose only statement is "deadflag=1;".

This is an easy case since the wording never varies. More typical examples would be:

> To say (something - number): (- print {something}; -).
> To sort (T - table-name) in (TC - table-column) order:
> (- TableSort({T}, {TC}, 1); -).

When the braced name of one of the variables in the phrase preamble appears, this is compiled to the corresponding I6 expression at the relevant position in the I6 code. So, for instance,

> say the capacity of the basket

might be compiled to

> print O17_basket.capacity;

because "{something}" is expanded to "capacity of the basket" (I7 code) and then translated to "O17_basket.capacity" (I6 code), which is then spliced into the original I6 definition "print {something};".

Braces "{" are of course significant in I6. A real brace can be obtained by making the character following it a space, and then I7 will not attempt to read it as a request for substitution.

Finally, note that while a normal I7 phrase definition can give a kind as what must be matched, e.g.,

> To release wild tigers into (arena - a room): ...

it is in general a bad idea, and will result in inefficient code, for an phrase defined using I6 to do this. Instead, if possible, match against "object", where any room, region, thing or direction will be a valid match:

> To release wild tigers into (arena - an object): ...

306
| Example Odins Making [is-are] and [it-they] say tokens that will choose appropriately based on the last object mentioned.

307
| Example Pink or Blue Asking the player to select a gender to begin play.

Suppose we would like to allow the player to choose a gender for the main character. We'd also like this to happen at the beginning of the game and outside the main parsing sequence. "When play begins" seems like a good place to put this. "Pink or Blue" When play begins: say "Should your character be male or female? >"; if men win, now the player is male; otherwise now the player is female; say paragraph break. Now a piece of Inform 6 code handles the unusual input. It's not necessary to understand this to use it, and the code should work for any question you'd like to ask the player. The first three words in quotation marks ('male', 'M', 'man'...) correspond to positive feedback; the later three words correspond to negative feedback. So "to decide whether men win" will be true if the player types one of the first three, and false if he types one of the last three. To decide whether men win: (- Question('male','M//','man','female','F//','woman') -) Include (- [ Question pos1 pos2 pos3 neg1 neg2 neg3 i; for (::) { if (location == nothing || parent(player) == nothing) read buffer parse; else read buffer parse DrawStatusLine; i=parse-->1; if (i==pos1 or pos2 or pos3) rtrue; if (i==neg1 or neg2 or neg3) rfalse; print "Please choose ", (address) pos1, " or ", (address) neg1, ". > "; } ]; -) Instead of examining the player when the player is female: say "Congratulations, you are a girl!" Instead of examining the player when the player is male: say "Congratulations, you are a boy!" The Room of Self-Knowledge is a room. "Mirrors cover every available wall-surface of this hexagonal chamber, allowing you to examine yourself from all angles."

Previous | Contents | Next