Inform 7 Home Page / Documentation


§7.4. Try and try silently

Chapter 2 noted that surveys of Inform source text showed that the three most popular phrases used by authors are "say", "if" and "now". The fourth most popular is "try", which allows us to trigger off actions ourselves, rather than waiting for the player to type something which generates them. Thus:

try (action)

This phrase makes the action, which has to be named literally, take effect now. Example:

Instead of entering the trapdoor, try going up.

It's as if the player had typed GO UP as a command. Note that the action has to be specific:

try eating something;

is not allowed, since it doesn't say exactly what is to be eaten.

The word "try" is intended to make clear that there is no guarantee of success. For example:

Before locking the front door, try closing the front door.

could go wrong in any number of ways - perhaps the door is closed already, perhaps it is not openable, perhaps somebody has wedged it open. It would be safer to write:

Before locking the front door:
    try closing the front door;
    if the front door is open, stop the action.

There's no need to say anything if closing didn't work, because the closing action will have done that already. A neater approach still is to use:

silently try (action)


or:   

try silently (action)

This phrase makes the action, which has to be named literally, take effect now, under the "silent" convention which means that routine messages aren't printed. Example:

try silently taking the napkin;

Silence is maintained only if this new action, the taking of the napkin, is successful (so if the napkin is successfully taken, the text "Taken." will not appear): if the action should fail, a suitable objection will be voiced as usual.

So now we have:

Before locking the front door:
    try silently closing the front door;
    if the front door is open, stop the action.

And this is neater because it won't produce a pointless "You close the front door." message.

* See Stored actions for how to store up actions as values and try those, too, so that isn't necessary to name the action as literally as in the examples above


arrow-up.png Start of Chapter 7: Basic Actions
arrow-left.png Back to §7.3. Before rules
arrow-right.png Onward to §7.5. After rules

*ExampleFine Laid
Making writing that can be separately examined from the paper on which it appears, but which directs all other actions to the paper.

*ExampleHayseed
A refinement of our staircase kind which can be climbed.