Key & Compass Blog

February 11, 2016

Affordances: Doors and Keys

Filed under: Interactive Fiction — Tags: — davidwelbourn @ 4:12 pm

This is the first in a series of planned posts about affordances in parser-based interactive fiction. Affordances are features that enhance the playing experience in some way, perhaps by making the work of IF less tedious, less frustrating, easier to play, more attractive, more interesting, or more fun. Affordances may be said to improve the play value of a game; reviewers will often point to these positive features as reasons why they liked a particular game.

For my first article on affordances, I’m going to start with the obvious topic: doors and keys. Long-time players of IF are quite familiar with the tedium of “UNLOCK DOOR WITH KEY. OPEN DOOR. E.” in older games, and now expect “E.” to do all that busywork with the key automatically. It may be helpful to list how we want the game to behave in various circumstances when attempting to go through a door:

  1. If the door is closed and locked: Try using any and all available keys in a reasonable way to automatically unlock the door.
  2. If the door is still locked: Report that there’s a locked door in the way.
  3. If the door is unlocked but closed: Automatically try opening it.
  4. If the door is still closed: Report that there’s a closed door in the way. Perhaps it’s jammed or guarded.
  5. If the door is (now) open: Go right through.

That first step glosses over a lot of fussy details. We want to try keys known to open the door first, which means the game has to remember if the player-character has successfully used a key before. We will also want to consider keys in our inventory before considering visible keys in the PC’s location. We probably want to automatically try taking a key if it’s not in our inventory, even if the key’s in a piranha tank. If we do pick up a key, we probably want to automatically put it into any keyring we already have. And once the key is in our inventory, there’s the question of availability; a key in a keyring is available for our use, but a key held by an evil gremlin in the birdcage we’re carrying probably isn’t available. So, let’s try to itemize all that:

  1. If this door doesn’t even use keys, skip all this. Don’t bother trying keys.
  2. Select a key:
    1. If there’s a key in our inventory known to open the door, select that key.
    2. If there’s a visible key elsewhere in our location known to open the door, select that key.
    3. If there’s a key in our inventory that will open the door, select that key.
    4. If there’s a visible key elsewhere in our location, select that key.
    5. Otherwise, no key is selected: Report that you don’t have a key for this door.
  3. If the selected key isn’t in your inventory, try taking the key. If the taking was successful and if you have a keyring, put the key into the keyring.
  4. If the selected key isn’t available: Report that you can’t use that key because of reasons (e.g.: evil gremlin).
  5. Otherwise: Unlock the door with selected key.

Note that (IMHO) we should only generate an automatic take-action when the key is outside our inventory. We shouldn’t have to bother taking the key out of our
keyrings, picnic baskets, and Soft-N-Fresh bathrobe pockets in order to use a key. Test for availablilty/touchability instead of testing it being directly in our hot little kleptomaniac hands.

Further things to consider:

  • Understand keycards as a separate class of keys. Only automatically try keycards in doors with the appropriate slots, and only try cut keys in doors with keyholes, eh?
  • You can automate entering an elevator car too. Don’t force a player to type “PUSH CALL BUTTON. WAIT. E.” when “E.” could accomplish the same thing.
  • Car doors, too, can be friendly. Don’t force a player to type “UNLOCK CAR DOOR WITH CAR KEY. OPEN CAR DOOR. ENTER CAR.” when “ENTER CAR” is good enough.
  • Don’t forget about automatic closing and locking of doors. When the PC is leaving their own home or exiting their own car, it’s perfectly reasonable to have the game automatically close and lock the door behind them, as long as they have the key.
  • Report what door(s) a key is for when the PC examines the key, assuming they know that info. Likewise, report what door(s) a key is for when the PC takes inventory.

If you’re writing in Inform 7, you’ll want to lookup the Locksmith extension by Emily Short. I haven’t looked at it, since I’m more of a player than an author, but I expect that it handles most, perhaps all, of the above.

So how’d I do? Are there any other affordances regarding doors and keys you’d like to see that I missed? Please comment below.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: