inform doors.. an alterna


Sat, 11 Nov 1995 13:33:00 -0500

A2> What advantages does the door_dir/door_to method have
A2>over this? I know my method works fine (as far as I can tell).

Here's some code from my first try at Inform, a game I'd tried writing
in Pascal and Prolog before finding Inform. (I've shelved till I finish
some smaller things; right now I've just got the opening few rooms
done.)

Object Courtyard "Courtyard"
with description [;
print "Your feet crunch on broken cobblestones as you traverse
this open space. \
All around you tower forbidding mountain ramparts, their
jagged peaks reaching up \
to pierce a steel grey sky. The mountain walls are broken
by a huge iron gate ";
if (castle_gate has open) print "leading south ";
else print "barring the way southward ";
"and a narrow crevice leading upwards to the northwest.";
],
s_to castle_gate, out_to castle_gate,
n_to hallway_into_ruin, in_to hallway_into_ruin,
nw_to narrow_crevice, u_to narrow_crevice,
has light;

Nearby ruined_castle "ruined castle"
with name "ruin" "ruins" "castle" "keep" "fortress" "hulk" "hulking"
"silhouette",
description "The front wall of the castle is crumbling, but
seems solid enough that it \
won't collapse at a touch. Only the first floor still stands,
but a single tower \
still balances precariously on the southwest corner. The
front door has also \
fallen, exposing a hallway leading north into the heart of the
ruin.",
initial "To the north, a hulking castle ruin is silhouetted,
black against the stark \
grey sky.",
door_dir n_to,
door_to hallway_into_ruin,
has static transparent door open;

Object hallway_into_ruin "hallway" ruined_castle
with name "hallway" "hall" "entry",
description "The hallway leads north into the heart of the
ruin.",
door_dir n_to,
door_to Entry_Hall,
has scenery open door;

You'll notice that I actually have three ways to enter the castle - you
can type "go north" or "go in" from the Courtyard, which moves through
the "hallway" door into the castle. Or you can type "enter castle", in
which case the door_to property points you to the "hallway" door again.
Or you can use the "hallway" door by typing "Enter hallway". Using your
system, I would have to code each of these doors seperately to enter the
castle, and if I decide later that something happens when you go in
(like a cold voice whispers "Go back!" or something) I would have to add
it to each door seperately. Note that this complex nest of doors
probably took me less time to progam then your single door did, and it's
more flexible. There are a lot of other things you can probably do that
I haven't thought of yet, but if you just start by rewriting the code
and you find something that would be easier to do with the doors system
as it is, you'll regret it.

Joe

* SLMR 2.1a * "There's still time to change the road you're on" - Led Z