Let's examine the shortest, simplest room possible:
simpleroom.c
inherit STD_ROOM_OB;
void create()
{
   ::create();
   set_short("Grey's workroom");
   set_long("Welcome to Grey's workroom.\n\n"+
     "You are in a small, barren room.  There isn't much to see here, "+
     "so consider taking one of the exits.");

   add_exit("east",  "/domains/std/rooms/equip");
   add_exit("north", __DIR__+"northroom");
}

Now let's take this apart and see what it does.

inherit STD_ROOM_OB;
This tells the MUD to base your object on the standard room code. This line is required if you wish to make a room.

void create() {
The "create" function is called when an object is loaded into memory. Think of it as the first program that runs after your computer reboots. The "create" function consists of everything in between the { and the }.

::create();
This tells the MUD to execute all the code contained in the create() function within STD_ROOM_OB. This is a very good thing to do! This "sets the stage" for the functions you're about to add. Forgetting to include this line can lead to unpredictable results.

set_short("Grey's workroom");
This sets what's called the "short description". This description appears in the Portal statusbar, and is displayed when the player enters the room if in "brief" mode. All objects should have a short description.

set_long("Welcome....");
The sets what's called the "long description". This description is displayed whenever the player types "look", and when the player enters the room if not in "brief" mode. All visible objects should have a long description. Invisible objects cannot be looked at, so they don't need a long description.

The MUD automatically performs linewrapping on descriptions (these are defined by the set_long function). To force a line or paragraph break, use the "\n" character. Using it once forces a simple carriage return, and using it twice forces a paragraph break.

add_exit("east", "/domains/std/rooms/equip");
This tells the MUD that when the player types "east", the player should be moved into the room defined by the file "/domains/std/rooms/equip.c". It is not necessary to type the ".c" extension when indicating an exit. The add_exit function also adds the "east" exit to the list of obvious exits displayed at the bottom of the long description.

add_exit("north", __DIR__+"northroom");
This is similar to the previous add_exit, except the __DIR__+ tells the MUD that the destination room, northroom.c, is contained within the same directory as the current file. This makes things a LOT EASIER! If your directory becomes renamed, you won't have to go through and update every single exit!


Finally, notice that every line of code ends in either a + or a ;. The semicolon indicates the end of a line. The + indicates that the line is continued on the next line (for readability purposes). Blank lines are also allowed (they are ignored by the compiler).


This page may be viewed from any browser, not just one from Redmond.
Last Modified: Jan 1, 2001
Page written by Dave Shay (how to contact me).
Page content copyright ©2000-2001 by Dave Shay. Do not copy without express permission.
Dungeons & Dragons is a registered trademark of TSR, Inc., a subsidiary of Wizards of the Coast.
D&D rules, races, classes, features, etc. used in accordance with the TSR, Inc. Internet Policy.