| Chapter 11: Phrases |

| 11.5. If

We now run through a few special phrases which control other phrases: causing them to repeat, perhaps, or to be skipped. These phrases are equivalent to the "control structures" of other computer programming languages: no system for interactive fiction can possibly be adequate unless it allows us to carry out arbitrary computations, so the pretence that Inform is not really a programming language must be dropped sooner or later. That time is now.

The phrase:

> if (... condition ...) then (... another whole phrase ...)

causes the phrase after "then" to be followed only if the condition holds. Some people prefer to use a comma, which is treated just the same:

> if (... condition ...), (... another whole phrase ...)

Because of this conventional use of a comma, it is a good idea to avoid using a comma in the condition itself:

> if opening, closing a door, ...

tends to confuse Inform.

There are many different forms of condition in Inform (and, as we shall see, we can easily add more), but the simplest is:

> (first value) is (second value)

As always, Inform checks that these two values are of kinds which can be compared. The following will produce an objection, for instance:

> if 10 is a door then say "Huzzah!"

since it makes no sense to ask the question, and the only result will be the baffled reply:

> Problem. In the line 'if 10 is a door then say "Huzzah!"' , I can't determine whether or not '10 is a door', because it seems to ask if a number is some sort of door.

This, however, would be fine:

> To comment upon (whatever - a thing):
> if whatever is transparent then say "I see right through this!";
> if whatever is an open door then say "Oh look, an open door!".

since "whatever" is known to be a thing, and Inform knows that things are indeed sometimes transparent and sometimes open doors.

Previous | Contents | Next