Login
Remember
IF Answers
Ask a Question

# How does punctuation work in Inform 7 code?

+1 vote
81 views
asked Mar 27 in Authoring by Juhana (246 points)
recategorized Mar 27 by Alex
When should you use periods, colons, semicolons and commas?

- inform7

commented Mar 27 by bg (692 points)
Conceivably someone could click on this question looking for an explanation of brackets or parentheses. Would it make sense to include or link to those as well?
commented Mar 27 by Juhana (246 points)
It would probably make the question too broad. The answer is already pretty long. Maybe make another question and link to that one.

## 1 Answer

+2 votes
answered Mar 27 by Juhana (246 points)

A rule header ends in a colon and inside the rule blocks individual lines end in semicolons. The last line ends in a period.

    After pushing the button:                   [<-- colon]
        say "I wonder what this button does.";  [<-- semicolon]
        now the machine is switched on;         [<-- semicolon]
        now the player is intrigued.            [<-- period]

The last line is the only place inside a rule block where a period can end the line. It signifies that the rule ends, so placing it anywhere else will cause a compilation error.

The last line can also end in a semicolon, but then there has to be at least one empty line right after the rule. Empty lines aren't allowed inside rule blocks.

Declarations always end in a period (full stop).

    The workshop is a room. A machine is in the workshop.

The period can be omitted if there is at least one empty line after the declaration, but it's advisable to always add the period to avoid errors when the empty line is accidentally deleted.

The period can be omitted if the line ends in a string that ends in punctuation.

    The description of the machine is "What could it be?"  [<-- period optional]

    Instead of jumping:
        say "Boing!"    [<-- period optional]

Only a period can be omitted in this case, never semicolons or other punctuation.

There are three valid ways to write control blocks (if, while, ...) The first is the so called "begin-end" style:

    Instead of pushing the button:
        if the machine is switched on begin;
          say "The machine is already running.";
        otherwise;
          say "You start the machine.";
          now the machine is switched on;
        end if.

Using this style all lines end in semic​olons, except for the last line of the entire rule which ends in a period. Indentation is optional but recommended for clarity.

The second is the "colon-and-indent" style:

    Instead of pushing the button:
        if the machine is switched on:              [<-- colon]
            say "The machine is already running.";
        otherwise:                                  [<-- colon]
            say "You start the machine.";
            now the machine is switched on.

Using this style the if condition ends in a colon as well as the "otherwise" line. (For more information see chapter 11.7. in Writing With Inform.)

The third way is to use a comma to separate the condition and the phrase.

    Check pushing the button:
        if the machine is switched on, say "The machine is already running." instead.

This works only when the condition acts on exactly one phrase.

## Related questions

- How do I print two distinct objects from a list (Inform 7) in a description?
- How do you use a hyperlink to paste text without (in effect) pressing enter? (Flexible Windows, Inform 7)
- How to show window background color in Quixe: background color property or text background? (Flexible Windows, Inform 7)
- How do you indent text in a window using Flexible Windows by Jon Ingold? (Inform 7)
- In Inform 7, how do you create a text window using Flexible Windows by Jon Ingold?

...