| Chapter 11: Phrases |

| 11.19. Review of Chapter 11: Phrases

1. Phrases are what we use to make changes to the world or send messages to the player in an Inform game. They are active ("award 3 points") rather than merely descriptive ("a shaggy dog"). They only make sense if we know exactly in what circumstances they will happen. For instance, a paragraph in the source text which simply reads

> Award 3 points.

is not allowed: when should the points be awarded - when play begins? Every turn? If certain actions are tried? The source doesn't indicate, so this usage of a phrase is not allowed. Similarly, the following does not make sense:

> The tennis ball is carried by the player. If Fido can see the tennis ball, say "Fido barks at the tennis ball." Understand "green" or "toy" as the tennis ball.

The "if..." phrase is one of the most useful, indicating that if a given condition holds, then then another phrase should take effect - in this case the condition is "Fido can see the tennis ball" and the other phrase tells the player that Fido barks. Again, though, we have not really said when all this happens: do we intend to check whether Fido can see the ball every turn? Or only in certain circumstances? So, just as with all other phrases, the "if..." phrase has to have a context:

> The tennis ball is carried by the player. Understand "green" or "toy" as the tennis ball.

> Every turn:
> If Fido can see the tennis ball, say "Fido barks at the tennis ball."

Now it is clear that the condition and phrase are to be applied every turn, and the text works properly.

Inform comes with numerous phrases built in, and the current stock can be seen in the Phrasebook Index of any project. Many phrases are needed only in special circumstances, but a few need to be in the repertoire of every Inform author: "if...", "say...", "now...", "while..." and "repeat...".

2. Phrases can be used in three circumstances: in rules, or to define new phrases in terms of simpler existing ones, or (for say phrases only) as substitutions in text.

A rule is made up of a series of phrases, so that for instance in the following text

> Instead of washing the dog:
> say "You give the dog a good scrub.";
> move the sponge to the player;
> change the dog to sopping wet.

"Instead of..." introduces a rule, which takes effect whenever the action "washing the dog" is tried. There are then three phrases ("say...", "move...", "change...") which take effect in succession. (Note the punctuation: the colon and then a list of phrases divided by semicolons.)

3. Inform defines a large number of phrases for us to use already, but we may sometimes need to create our own. A new phrase looks like a rule, but begins with "To" - it is a list of instructions saying how to do something. For instance:

> To reward persistence:
> award 5 points;
> say "Your persistence deserves a bonus. Keep up the good work."

This creates a new phrase, "reward persistence", in terms of (in this case) two existing ones. We can then use "reward persistence" in other rules and new phrases. Other examples might be:

> To empty the player's luggage: ...
> To remove points from (character - a person): ...
> To remove (point value - a number) points from (character - a person): ...
> To make (character - a person) lose (point value - a number) points in the eyes of (voter - a person): ...

Some phrases are complete in themselves, and have wording which never varies: for instance, the definition above means we would have to write exactly this -

> empty the player's luggage;

- to achieve the emptying result. No variant is accepted: "empty Joe's luggage" does not match the definition, nor even "empty player's luggage", because even the "the" is compulsory.

Alternatively, a phrase can require some additional input, in which case we must fill in the blanks of the phrase with specific values or names:

> remove points from James.
> remove 10 points from James.

4. Say phrases are those which begin with the word "say", and they can be used in one more circumstance: in square brackets as a text substitution. For instance, we might define

> To say Greek small letter beta: ...
> To say alphabet soup: ...
> To say age of (character - a person) in base six: ...

As well as being used like any other phrase, these can also appear inside any text as a substitution. For instance:

> The printed name of the polystyrene beta is "giant polystyrene [Greek small letter beta] sign".

Here there's no rule in sight, but Inform does not need one, because it knows exactly when this phrase takes effect - when the text is printed.

Say phrases can also contain blanks to be filled in, so

> say "Joey is [age of the noun in base six]."

would fill in the noun as "the character" in "To say age of (character - a person) in base six", determine the correct answer, and print it for the player. Because to say phrases can be arbitrarily complex, they are convenient ways to introduce random variations or bring in information about other aspects of the world.

5. Phrases to decide are different again. These phrases do not normally do something, but instead find something out. Examples include:

> To decide whether the cock has crowed:
> To decide whether (emperor - a man) rules wisely:
> To decide what number is the highest bid:
> To decide what number is the favourite number of (character - a person):
> To decide what colour is the prettiest colour:
> To decide what colour is the favourite colour of (character - a person):

These phrases make no sense on their own and instead are used to fill out conditions or supply values for other phrases to use. For instance, it would make sense for a rule to include the phrase "say the highest bid" as one of its instructions, but "the highest bid" on its own would be like a rhetorical question. It mentions something without indicating what to do about it. The above examples might be used like so:

> if the cock has crowed, milk the cows.
> if Claudius rules wisely, deify Claudius.

6. Phrases are not always the most succinct way to teach Inform how to make decisions. Sometimes it is neater to define new adjectives (see Chapter 5). For instance

> To decide whether (jar - a container) is empty: ...

has a very similar sense to

> Definition: a container is empty if...

but the adjective defined in the second case can be used more flexibly. Both ways to introduce this idea will allow us to write

> if the vase is empty...

but with the defined adjective we are also allowed to use "empty" in combination with nouns and other adjectives:

> Before taking the empty vase:...
> Instead of inserting something into an empty dirty vase:...

In general, if we are contemplating a "to decide whether..." phrase about a single room or thing, it is more efficient to define an adjective instead.

7. Phrases which do something may also followed by a phrase option set off by commas. (Phrases to say are not allowed these, and they tend to lead to confusion if used in phrases to decide, although it is not strictly against the rules to try this.) Phrase options are useful if we have two very similar tasks to perform, which share most of the same instructions.

Previous | Contents | Next