door_dir cuts down on the code size. You code works fine, but suppose you
had multiple locked doors in the game. Would you really want to repeat
this each time? (Okay, you could shorten that by adding a Locked_Door_Class,
but door_dir exists to shorten the code even further.)
Here's an example:
Object Room "Example Room"
with description "This room demonstrates the use of a locked door.",
n_to Locked_Gate,
has light;
Nearby Locked_Gate
with name "locked" "gate",
description "A simple locked gate, typical of the kind found in \
adventure games.",
door_dir n_to,
door_to Beyond_Locked_Gate,
key Gate_Key,
has static door openable locked;
Nearby Gate_Key
with name "gate" "key" "metal",
initial "A metal key lies on the ground nearby.",
description "It's a key. For unlocking things.";
Object Beyond_Locked_Gate "Beyond the Locked Gate"
with description [;
Deadflag = 2;
"Congratulations! You have just gotten beyond the gate and \
successfully implemented your first locked door in Inform!";
],
has light;
-- C.E. Forman ceforma@rs6000.cmp.ilstu.edu Read the I-F e-zine XYZZYnews, at ftp.gmd.de:/if-archive/magazines/xyzzynews! * Interactive Fiction * Beavis and Butt-Head * The X-Files * MST3K * C/C++ *