11.6. If

| Chapter 11: Phrases |

| 11.6. If

Inform's most powerful phrases are those which control the others, making them repeat, or be skipped.

if (a condition) , (a phrase)
or: if (a condition):

This phrase causes the single phrase, or block of phrases, following it to be obeyed only if the condition is true. (If the condition must contain a comma for some reason, the block form should be used.) Example: if the red door is open, say "You could try going east?"

The sense of an "if" can be reversed by using the word "unless" instead:

unless (a condition) , (a phrase)
or: unless (a condition):

This phrase causes the single phrase, or block of phrases, following it to be obeyed only if the condition is false. (If the condition must contain a comma for some reason, the block form should be used.) Example: unless the red door is closed, say "You could try going east?"

"Unless" is clearly unnecessary, but it can be a good way to make the source text easier for humans to read.

As we have seen, there are many different forms of condition in Inform. They usually take a form quite like an assertion sentence, except that they're questions and not statements of fact. For example:

> if the score is 10, ...
> if all of the people are in the Atrium, ...

Questions like this are checked by Inform to see if they make sense. The following doesn't, for instance:

> if 10 is a door, say "Huzzah!";

This produces the baffled reply:

> Problem. In the line 'if 10 is a door, 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.

| Previous builds allowed the form: if (a condition) then (a phrase)
This phrase is now deprecated and is exactly equivalent to: if (a condition), (a phrase) Use a comma instead of "then", or else use a block.

Previous | Contents | Next