§11.7. Begin and end

In practice it is not enough to apply "if" to a single phrase alone: we want to give a whole list of phrases to be followed repeatedly, or to be followed only if a condition holds.

We do this by grouping them together, and there are two ways to do this. One is as follows:

To comment upon (whatever - a thing):
    if whatever is transparent, say "I see right through this!";
    if whatever is an open door:
        say "Oh look, an open door!";
        if whatever is openable, say "But you could always shut it."

Here we group two phrases together under the same "if". Note that the comma has been replaced by a colon, and that the indentation in the list of phrases shows how they are grouped together. In the example above, the source moves two tabs in from the margin; the maximum allowed is 25.

Indentation is the convention used in this manual and in the examples, but not everybody likes this Pythonesque syntax. So Inform also recognises a more explicit form, in which the beginning and ending are marked with the words "begin" and "end":

To comment upon (whatever - a thing):
    if whatever is transparent, say "I see right through this!";
    if whatever is an open door
    begin;
        say "Oh look, an open door!";
        if whatever is openable, say "But you could always shut it.";
    end if.

(Pythonesque because it's a style popularised by the programming language Python, named in turn after "Monty Python's Flying Circus".)


arrow-up.pngStart of Chapter 11: Phrases
arrow-left.pngBack to §11.6. If
arrow-right.pngOnward to §11.8. Otherwise

The main point here is that we need to figure out where the stack meets the floor:

paste.png "Princess and the Pea"

The Topmost Turret is a room. A mattress is a kind of supporter. A mattress is always enterable. A mattress is portable.

A large mattress is a mattress in the Turret. A medium mattress is a mattress in the Turret. A small mattress is a mattress in the Turret.

Instead of sleeping when the player is on a mattress (called the bed):
    let the item be the bed;
    while the holder of the item is not a room:
        let the item be the holder of the item;
    say "You can still feel something very uncomfortable under [the item]."

Instead of sleeping:
    say "You can't sleep standing up!"

Instead of looking under a mattress, say "You scout around, but are unable to determine what's causing you this discomfort. If only your maid Winnie were here. She's very good at this."

Test me with "sleep / enter small / sleep / get up / get small / put small on medium / get on small / sleep / get up / g / get medium / put medium on large / get on small / look / sleep".

*ExamplePrincess and the Pea
The player is unable to sleep on a mattress (or stack of mattresses) because the bottom one has something uncomfortable under it.

The main point here is that we need to figure out where the stack meets the floor:

paste.png "Princess and the Pea"

The Topmost Turret is a room. A mattress is a kind of supporter. A mattress is always enterable. A mattress is portable.

A large mattress is a mattress in the Turret. A medium mattress is a mattress in the Turret. A small mattress is a mattress in the Turret.

Instead of sleeping when the player is on a mattress (called the bed):
    let the item be the bed;
    while the holder of the item is not a room:
        let the item be the holder of the item;
    say "You can still feel something very uncomfortable under [the item]."

Instead of sleeping:
    say "You can't sleep standing up!"

Instead of looking under a mattress, say "You scout around, but are unable to determine what's causing you this discomfort. If only your maid Winnie were here. She's very good at this."

Test me with "sleep / enter small / sleep / get up / get small / put small on medium / get on small / sleep / get up / g / get medium / put medium on large / get on small / look / sleep".

The main point here is that we need to figure out where the stack meets the floor:

paste.png "Princess and the Pea"

The Topmost Turret is a room. A mattress is a kind of supporter. A mattress is always enterable. A mattress is portable.

A large mattress is a mattress in the Turret. A medium mattress is a mattress in the Turret. A small mattress is a mattress in the Turret.

Instead of sleeping when the player is on a mattress (called the bed):
    let the item be the bed;
    while the holder of the item is not a room:
        let the item be the holder of the item;
    say "You can still feel something very uncomfortable under [the item]."

Instead of sleeping:
    say "You can't sleep standing up!"

Instead of looking under a mattress, say "You scout around, but are unable to determine what's causing you this discomfort. If only your maid Winnie were here. She's very good at this."

Test me with "sleep / enter small / sleep / get up / get small / put small on medium / get on small / sleep / get up / g / get medium / put medium on large / get on small / look / sleep".

*ExampleMatreshka
A SEARCH [room] action that will open every container the player can see, stopping only when there don't remain any that are closed, unlocked, and openable.