Since I was having a bit of trouble lately in making doors in Inform 6 work, I thought it might be a nice idea to write down my experiences for my own memory, and of course for the benefit of other I6 novices who could find some advice useful.
Doors are I6′ way of connecting rooms in any non-trivial way. As such, a bridge, a teleport system or such should be implemented as doors, too.
Since I’m writing such a sequence right now, let’s assume you are at an inn on the upstairs floor, which is aptly named inn_upstairs
, and there is one other room to the east, namely chamber
.
The trivial way would be to connect those simply with an exit from inn_upstairs
:
e_to chamber
which gives you ready access from inn_upstairs
to chamber
— but this is of course not what we want.
Rather, we’d like to have a door. First of all, we need to create it — which is done by inserting an object with the attribute has door
and placing it in the room which we want to leave through said door (we’ll call this the “source room”) — in our exmaple, the room to leave is inn_upstairs
. Now we need to implement the actual door behaviour, which is a three-step process:
- Define the door as the exit of the source room in the direction of the adjoining room, which in our case lies to the east — hence:
e_to the_door
replaces the previous direct exit in its definition.
- Secondly, we need to declare to which room the door will lead, provided it’s open — ie, define the door with
door_to chamber
- Finally, we must also state into which “direction” the door is leading, namely
door_dir e_to
I’m still a bit puzzled as to the purpose of the third step. My guess is it has to do with the behaviour that once a door is open, you can walk through it like through a regular exit without re-opening it every time, ie the original’s room e_to
is now replaced by the door_dir
.
Your door needs to be given the attribute openable
so that it can be opened and closed and will behave as expected. To determine its initial state, you can give it the attribute open
. (Without that it will initially be considered closed.)
To spice things up a bit more, you can define the door lockable
(and locked
, at your whim). It can then be locked or unlocked with any object you may have defined elsewhere, by defining it as the key for the door: with_key room_key
, for example.
The complete code for rooms, door and key looks like this: (Note that the key is defined elsewhere, but since really anything can be the key, there’s nothing special about it.)
!##########################################################################
object inn_upstairs "A tiny landing"
with initial "You climb up the narrow stairs -- hardly more than a
ladder -- to arrive on the landing.",
description "A tiny landing on the tavern's first floor. While the
stairs lead down to the hall of the inn, one door leads to a room
south of you.",
e_to the_door,
d_to inn,
has light;
!##########################################################################
object the_door "room door" inn_upstairs
with name "door",
description "A door to one of the guest's chambers.",
when_closed "Another locked door bars your way to a room east.",
when_open "An open door leads east to the chamber behind.",
after[;
unlock: give self open;
],
door_to chamber,
door_dir e_to,
with_key room_key,
has door lockable openable locked static;
!##########################################################################
object chamber "A chamber in the inn"
with initial "You enter the modest small room and wait for a second,
until your eyes are accommodated to the bit of light coming
through a little window.",
description "The room is obviously occupied by a female guest, but
the lady isn't present.",
w_to inn_upstairs,
has light;
The lines
after[;
unlock: give self open;
],
may require a bit of extra explanation:
Per default, locking/unlocking and closing/opening a door (or any container, for that matter) are two seperate actions. With the after
rule the opening follows the unlocking automatically, to make it easier and quicker on the player, and since it can be assumed that if the player unlocks the door, he’ll also want to open it (in this scenario).
Note that trivial exits and doors have one thing in common: Per default, they’re one-way in I6, which means that a door which connects room A to B does not automatically also give access from room B to A. Rather, you must implement a second door back from B to A (and ideally one which shares its locked/open state with the first door…). (In my example I went the easy way and simply gave the chamber
visited through the door a “regular” exit back to inn_upstairs
. In the current scenario, it makes little sense for the player to for example lock himself in the chamber.) I presume the one-way feature was designed with “unusual” doors like trap-doors in mind. You can also find libraries for I6 out there which help in implementing two-way doors.