< Prev page
Contents
Next page >
Get me outta here! (Directions)
Feeling stir crazy in the Boring Room? Want to stretch your legs? Let's go for
it! Let's double the room count of our game! Add the following object definition
after RedButton:
Object InterestingRoom "Interesting Room"
with name "painting" "picture",
description "What makes this room interesting? Well, for starters,
it's a different room! There's also a picture hanging on one wall,
but it's not a very interesting picture.",
e_to BoringRoom
has light;
Now add a comma to the end of the description property of BoringRoom
and this line before the has clause:
w_to InterestingRoom
Compile and run. Enjoy your newfound freedom. After you get tired of going east
and west over and over again (which should take about five seconds), quit the game
and let's look at what we did.
Directions are specified as properties
It's that simple. If you want one room to be connected to another via one of the
ten basic directions, simply use that direction's abbreviation + "_to"
as the property name and the name of the destination room's constant as the value.
Directions are implemented as objects
And there are actually twelve of them. Here is a list of the directions and
their corresponding objects and properties:
Direction | Object | Property |
north | n_obj | n_to |
south | s_obj | s_to |
east | e_obj | e_to |
west | w_obj | w_to |
northeast | ne_obj | ne_to |
southeast | se_obj | se_to |
northwest | nw_obj | nw_to |
southwest | sw_obj | sw_to |
up | u_obj | u_to |
down | d_obj | d_to |
in | in_obj | in_to |
out | out_obj | out_to |
in and out are special, and you normally don't include them
as available directions. out is automatically provided if the player
is inside or on top of an object. How do you allow the player to get in (or
on) an object? Give the object enterable. (You must also give it
supporter if you want the player to be able to get on it instead of
in it.)
The directions are all children of the compass object. They can be
removed from this object, and new directions can be added. I won't cover that
in this guide, but be aware that it can be done.
Why make directions objects?
Directions are objects so that they can be tested. For example, when a player
types "NORTH," or simply "N," Inform generates the action <Go n_obj>.
We haven't covered actions yet, but trust me that Go is the verb and
n_obj is the first noun, which is stored in a variable called noun.
When the player enters a room, code attached to that room object can check to see
which direction the player used to enter the room. Let's say there is a trap door
in the south end of a room. If the player enters the room from the south, that is,
the player went north from the room he was in, the room can see that a
<Go n_obj> action brought the player here and it can dump him into
the dungeon.
You can't get there from here
Remember that computers do only what you tell them. Just because you can go west
from the Boring Room into the Interesting Room, the game doesn't know (or assume)
that you can go east from the Interesting Room to the Boring Room unless you
specifically say so. That's why we added the w_to property to
BoringRoom.
< Prev page
Contents
Next page >
This page hosted by
Get your own Free Home Page
And yes, folks, it's really free. I'm too cheap to pay for this.