___________________________________

A TADS Tutorial: Lesson One

Rooms & Properties

___________________________________

Introduction

Today we begin the process of writing text-adventure games. At a minimum, all these games must have locations for the player to explore. Here is a sample transcript from an extremely simple story with two locations, to give you an idea what the interactions are like:
Outside cave
   You're standing in the bright sunlight just outside of a large, dark,
forboding cave, which lies to the north.

>GO NORTH
Cave
   You're inside a dark and musty cave.  Sunlight pours in from a passage to
the south.

Actually, walking around is so common, the player can omit the verb "GO" and just use compass directions to indicate where he wants to go.
>SOUTH
Outside cave

>LOOK
Outside cave
   You're standing in the bright sunlight just outside of a large, dark,
forboding cave, which lies to the north.

Notice that when the player returns to a location he has already been, it just gives him the name of the location. If he wants to read the whole description again, he needs to type "LOOK." Many commands can be abbreviated, such as "N" for north and "L" for "LOOK."
>N
Cave

>L
Cave
   You're inside a dark and musty cave.  Sunlight pours in from a passage to
the south.

There are several special commands available to the player. "INVENTORY" or "I" which lists what the player is carrying. "SAVE" creates a bookmark in the story, and "RESTORE" accesses those bookmarks.
>INVENTORY
You are empty-handed.

___________________________________

TADS

Writing a computer program that can handle all the interactions in just this simple example can be extraordinarily challenging. First, the program must prompt the user for input, then analyze or "parse" the command that the player has typed in. It must identify the verb, the direct object, and other parts of speech. Then it must try to make sense out of the command, and output the appropriate response.

Fortunately, a programming library called TADS (Text Adventure Development System) already does a lot of this. It handles the input/output and the grammatical parsing. All you have to do is program the locations, objects and characters. This allows you to concentrate on the actual content of your story.

TADS is free and can be downloaded from the Internet at http://www.ifarchive.org/programming/tads2/executables/. Select the file that will work with your operating system and decompress it in its own directory or folder on your computer.

___________________________________

Always Start With a Map

Good programmers always plan out what they are going to program before they start typing. Before programming your story, you must start with a map of all the locations in your story and illustrate how they connect to one another. Here is what the above example would look like:
Map

___________________________________

Using the Editor

To type a program, you must use a text editor. You may use any editor you wish, such as Wordpad, which comes with Windows, or SimpleText, which comes with the Mac OS. However, I suggest you look at a few of the, very sophisticated, text editors that are available on the Internet for free, like PFE (Programmer's File Editor) for WinTel boxes, or BBEdit Lite for Macintoshes.

A text editor is a bit different from a word processor (like Word Perfect). Unlike word processors, editors don't embed the text with font and formatting information that might confuse the program compiler. Editors often contain a number of other features useful to programmers such as line number information and smart indenting. However, you can expect many of the editing features to work much like a word processor (Home key, End key, Page Up, Page Down, Delete, Backspace, Insert, text highlighting, and cut and paste all work the same). Once you have started your editor, select File ... New. Then File ... Save the empty file as exercise1.t -- all TADS program names should end in ".t".

Type the following program exactly as written here. Use the tab key to indent.

#include <adv.t>
#include <std.t>

startroom : room
  sdesc = "Outside cave"
  ldesc = "You're standing in the bright sunlight just outside of a
  large, dark, forboding cave, which lies to the north. "
  north = cave
;

cave : room
  sdesc = "Cave"
  ldesc = "You're inside a dark and musty cave.  Sunlight pours in from a
  passage to the south. "
  south = startroom
;

This is the entire program for the example. This program illustrates what object-oriented programming is all about. Object-oriented programmers create classes that provide general behavior, and then create objects that are specific instances of the more general classes. The objects have properties which distinguish them from one another.

Let's discuss the program briefly, line-by-line.

#include <adv.t>
#include <std.t>

These two statements include the files adv.t and std.t which provide many built-in classes for you to use when programming your story. For example, adv.t contains the definition of the class room, which is used twice in the above program.
startroom : room

This line declares an object called startroom which is an instance of the class room. TADS already knows how rooms work, so you just need to define a few properties to make this room unique. Every story must have exactly one room called startroom, and that's where the player will start.
 sdesc = "Outside cave"

This line defines the "short description" (sdesc) property of startroom.
 ldesc = "You're standing in the bright sunlight just outside of a
  large, dark, forboding cave, which lies to the north. "

This line defines the "long description" (ldesc) property of startroom. Note that there is a space after the period. That is because another sentence might be printed out after the long description, so we want to make sure we have a space there.
 north = cave

This says that the room object called cave lies to the north of this room. TADS understands the directions north, south, east, west, ne, se, nw, sw, up, down, in, and out.
;

The semicolon says that you're done defining the startroom object.
cave : room
  sdesc = "Cave"
  ldesc = "You're inside a dark and musty cave.  Sunlight pours in from a
  passage to the south. "
  south = startroom
;

Another object called cave, also a room, is defined. It's much like the other room, but with different information filled in for each of its properties.

___________________________________

Compiling

Once you have finished writing your program, don't forget to save it. The next step is to compile your program into a game file. On a command-prompt OS, return to the command prompt and type tc followed by the program name. For example: "tc exercise1.t". If you're using a GUI OS, launch the compiler and choose compile from a menu, then navigate to the program. Hit Okay. The compiler will display any error messages from your compile.

If you didn't receive any error messages, then your program (sometimes called source code) was compiled into a game file. Look for your game file (exercise1.gam) in the same directory where you saved exercise1.t. Double-click on it to test your program (or type "tr exercise1.gam" from the command prompt). Does your program respond just like the sample transcript? What happens if you type an invalid direction like "GO EAST?" Experiment for a while.

___________________________________

Exercise

Start a new file called "home1.t". Draw a map containing at least four interconnecting locations. Use a fantastical setting, or use your house if you can't think of anything. Then write the program for the locations you have mapped out. Use good writing skills and try to come up with interesting descriptions for each of the locations. Compile your program and have a friend test it.

Read the "Suspect" sample transcript to see what a more complex interactive game is like.

See the Sample Source Code
Go on to Lesson Two
See the Table of Contents

The Text Adventure Development System
Version 2.2
This page is part of Mark Engelberg's TADS Tutorial
Copyright © 1999 Mark Engelberg