Inform 7 Home Page / Documentation


§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!"' Reveal.png, I can't determine whether or not '10 is a door', because it seems to ask if a number is some sort of door.


arrow-up.png Start of Chapter 11: Phrases
arrow-left.png Back to §11.5. Conditions and questions
arrow-right.png Onward to §11.7. Begin and end