Welcome to Adventure: Lesson 3 (Doors, Keys, and Text with Variations)

Introduction

This is the third in a series of quick-start Inform 7 tutorials using examples from Colossal Cave Adventure. More information about this tutorial series can be found here: A Quick-Start Guide to Inform 7.

Making Doors

In Inform 7, a door is a thing that connects two rooms by way of a direction. The code for a basic door might look like this:

There is a room called My Office.
There is a room called The Hallway.
A wooden door is a door. The wooden door is east of My Office and west of The Hallway.

This will produce a basic door that you can walk through by way of a direction, or by entering the door. The player can open and close the door at will. The player will attempt to open a closed door automatically before walking through it, and the player will stop entirely if the door is locked.

example door behavior

As with other things, you can learn about the properties of a door by using the SHOWME debug command.

showme example door

Doors are automatically fixed in place. Doors also have a few special properties of their own, including open/closed, openable/unopenable, and locked/unlocked.

A Door By Any Other Name

A door doesn’t have to be called a “door”, and many are not. The stairs between At Top of Small Pit and In Hall of Mists are a door that cannot be opened or closed. The source code:

There is a room called At Top of Small Pit.
There is a room called In Hall of Mists.
Some rough stone steps are an open unopenable door. Some rough stone steps are down of At Top of Small Pit and up of In Hall of Mists.

Multiple Descriptions for One Door

The appearance of the stone steps changes depending on whether you are in At Top of Small Pit or in In Hall of Mists.

steps description

We can replicate this effect by giving the steps an initial appearance with two built-in states, like so:

The initial appearance of some rough stone steps is “Rough stone steps lead [if the location is At Top of Small Pit]down the pit[else]up the dome[end if].”

By default, the Inform 7 term “location” means “location of the player”, which means the room the player is currently in. But it doesn’t have to be the player. Consider this source code:

The initial appearance of some rough stone steps is “Rough stone steps lead [if the location is At Top of Small Pit]down the pit[else]up the dome[end if][if the location of the player is the location of the food]. It looks like a lovely place to sit down and eat some tasty food[end if]. “

Here’s the result.

steps for tasty food

You can also affect the description of a door based on a property. Going back to the first example:

There is a room called My Office.
There is a room called The Hallway.
A wooden door is a door. The wooden door is east of My Office and west of The Hallway.
The initial appearance of the wooden door is “A boring wooden door leads out of the room. The door is [if the wooden door is open]open[else]closed[end if].”

This kind of description change is not door-specific. It can be enacted on any piece of text, including room and object descriptions. For example, you could change the initial appearance of the bear based on whether or not the food is in the room:

The initial appearance of the bear is “There is a ferocious cave bear eying [if the location of the tasty food is the location of the bear]the tasty food[else]you[end if] from the far end of the room!”

Altering text on the fly is an incredibly powerful tool that deserves far more attention than it will receive in this quick-start tutorial series. It is covered comprehensively in chapter 5 of the Inform 7 manual.

A One-Way Door

At the very beginning of Adventure, instead of going east, you can type “go building” to enter the building, so the building is clearly a kind of door. But once you are in the building, you cannot type “go building” to exit the building again. This is a one-way door.

Here is an updated version of the code to connect End of Road and Inside Building.

There is a room called At End of Road.
There is a room called Inside Building.
The well house is an open unopenable door. The well house is inside of At End Of Road. Through the well house is Inside Building. Understand “building” as the well house.
Outside of Inside Building is At End of Road.

Note that “Inside of At End Of Road is Inside Building.” is no longer part of the source code. Leaving it in would produce an error, because Inform 7 would see that going inside from At End Of Road reached both a door (the building) and a room (Inside Building).

Doors that Lock and Unlock

At Slit in Streambed, there is a locked steel grate. The grate can only be unlocked with the keys. Here is one way to set this up:

There is a room called Outside Grate.
There is a room called Below Grate.
The steel grate is a locked lockable door. The steel grate is down of Outside Grate and up of Below Grate.

Here’s the result:

locking and unlocking the grate

Note the debug command PURLOIN, which will move an object from wherever it is in the game into your inventory. It is very useful for things like testing a key that you have not actually placed in a room (as is the case with the set of keys in the source code above.)

Containers that Lock and Unlock

Like doors, containers can be locked and lockable, and they can be unlocked with a matching key. This is useful in a wide variety of ways, although none of them are exemplified in Adventure.

Further Reading

To learn more about doors, keys, and text with variations, see the following parts of the Inform 7 manual:

§3.12. Doors
§3.13. Locks and keys
§5.6. Text with variations

Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *