A TADS Tutorial: Lesson Three
Items
Review
By now, you should have successfully compiled the program from Lesson 1, and should be able to create a program based on your own map, using room descriptions from your imagination. Hopefully, you've also had the opportunity to begin playing the game "The Plant," and making a map of the game as you play it. If you have not yet finished playing "The Plant," I urge you to continue playing it after you have completed this lesson's exercise.
Decorations
If you've played "The Plant," you now realize that interactive fiction is more than just a bunch of rooms that you can walk around in. The rooms need to be filled with objects and characters to interact with. In this lesson, you'll learn how to add certain kinds of objects to your rooms.The simplest kind of object to add is called a decoration. A decoration is an item in the game that you can "LOOK AT" or "EXAMINE," but has no actual function in the game. Usually, a decoration is a way to provide more information to the player about something in the room description. Decorations are immovable and cannot be manipulated in any way, but they can be referred to and inspected.
Here is a sample transcript from a room containing a few decorations:
Now let's take a look at the exercise3.t program for this room:Fireplace You are standing in front of a brick fireplace. Above the fireplace is a dusty mantle. >LOOK AT THE BRICK FIREPLACE A warm fire crackles and glows in the fireplace. >EXAMINE THE MANTLE The mantle is covered with a thick layer of dust. >LOOK AT THE DUST The dust has clearly been undisturbed for years. >GET DUST The dust isn't important.Okay, now that we've seen the whole program, let's take a look at the fireplace line-by-line:#include <adv.t> #include <std.t> startroom : room sdesc = "Fireplace" ldesc = "You are standing in front of a brick fireplace. Above the fireplace is a dusty mantle. " ; fireplace : decoration location = startroom noun = 'fireplace' 'fire' adjective = 'brick' sdesc = "fireplace" ldesc = "A warm fire crackles and glows in the fireplace. " ; mantle : decoration location = startroom noun = 'mantle' adjective = 'dusty' sdesc = "mantle" ldesc = "The mantle is covered with a thick layer of dust. " ; dust : decoration location = startroom noun = 'dust' sdesc = "dust" ldesc = "The dust has clearly been undisturbed for years. " ;Just like with rooms, every object must start with a one-word programming name which we'll use to refer to the object throughout our program.fireplace : decorationThis first property name is one you haven't seen yet. location is used to describe where the item is located. The property value must be the programming name for one of the rooms in the program.location = startroomThis property is used to teach new vocabulary to the parser. List here all the nouns that the player might use to refer to this object. Each noun is enclosed in single quotes, not double quotes. This is very important; the single quotes tell the program that it is a vocabulary word, and not a message to print out to the user.noun = 'fireplace' 'fire'This property also introduces new vocabulary words that the parser needs to be able to recognize. List here, enclosed in single quotes, all words that might be used as modifiers to describe the object. In other words, the noun and adjective properties together teach the computer to recognize all the following commands:adjective = 'brick'LOOK AT THE FIREPLACE.(This last command doesn't make much sense, but it's good to know that the parser will still be able to figure out what the player means if this is typed in).
LOOK AT THE FIRE.
LOOK AT THE BRICK FIREPLACE.
LOOK AT BRICK FIRE.Now we're back to properties that you've seen before. Just like with the room objects, the sdesc is the "short description" of the object. This is the string that the program will use if it needs to print out information about the object (like "The fireplace is not important.")sdesc = "fireplace"This is the "long description" of the object. This is the message that the player will see if he examines or looks at the object.ldesc = "A warm fire crackles and glows in the fireplace. "Every object is always terminated by a semicolon.;Reminder: All internal programming names are one word long, and are never enclosed in quotes. All vocabulary words are enclosed in single quotes. All messages that the user will see are enclosed in double quotes.
Readable Objects
Let's add a readable object to our program:Notice that this object is derived from the readable class (look after the colon on the first line). readable objects can be picked up, looked at, and read. We don't need to add the invitation to the room description because all takeable objects are automatically listed after the room description. Let's compile the program and see how it looks when we run it:invitation : readable location = startroom noun = 'invitation' adjective = 'party' sdesc = "party invitation" ldesc = "You are cordially invited to attend a Halloween costume ball at the haunted mansion. The party starts at 8PM. RSVP. " ;Fireplace You are standing in front of a brick fireplace. Above the fireplace is a dusty mantle. You see a party invitation here. >READ THE INVITATION You are cordially invited to attend a Halloween costume ball at the haunted mansion. The party starts at 8PM. RSVP. >GET THE INVITATION Taken. >INVENTORY You have a party invitation. >LOOK Fireplace You are standing in front of a brick fireplace. Above the fireplace is a dusty mantle. >DROP THE INVITATION Dropped. >LOOK Fireplace You are standing in front of a brick fireplace. Above the fireplace is a dusty mantle. You see a party invitation here.
Overriding Default Property Values
The built-in TADS classes define many default property values for you. Usually, these defaults work well and you don't have to do anything to use them, but sometimes you may want to override the defaults to get more specialized behavior.For example, the readable class defines a default property called readdesc, which is the message that the player gets when he reads the object. By default, readdesc is just a copy of ldesc, so the player gets the same message whether he types "LOOK AT" or "READ." But if you want the player to get a different message, just use a different readdesc message from the ldesc message.
As another example, most items in the game, including readable items, have a default property called adesc. By default, this property just stores a message which is the same as sdesc with "a " stuck in front of it. So the party invitation, for example, has a default of:
This message is used to list the item properly when describing the room:adesc = "a party invitation"When you want the default, you don't have to do anything, but there are certain item names that wouldn't look right if you just stuck an "a " in front. Here is an example of a readable item that overrides the readdesc and ldesc properties for special behavior. Try adding this to your exercise3.t:You see a party invitation here.If you compile and run the program, you should get the following:photo : readable location = startroom noun = 'photo' adjective = 'autographed' 'autograph' sdesc = "autographed photo" adesc = "an autographed photo" ldesc = "This black and white photo of a snow-capped mountain appears to be autographed in the lower-right corner. Although the handwriting is messy, you could probably read the message if you tried. " readdesc = "Reality is better than our best fantasies. -- Ansel Adams" ;Fireplace You are standing in front of a brick fireplace. Above the fireplace is a dusty mantle. You see a party invitation and an autographed photo here. >LOOK AT THE PHOTO This black and white photo of a snow-capped mountain appears to be autographed in the lower-right corner. Although the handwriting is messy, you could probably read the message if you tried. >READ THE PHOTO Reality is better than our best fantasies. -- Ansel Adams
Multiple Inheritance
When you create an item of a certain class we say that it inherits behavior from that class. It is possible to create an item that inherits behavior from more than one class.For example, we've already discussed the readable class which defines default behavior for readable objects that can be picked up. There is also a class we haven't discussed yet called fixeditem which defines default behavior for unmoveable objects. By combining the behavior of the two classes, we can get an object that is readable, but can't be picked up.
Notice on the first line that both fixeditem and readable are listed, separated by a comma. This indicates that the calendar should get its behavior from both classes. Since the wall calendar can't be picked up, it won't automatically be listed after the room description. So we need to go back to the room description and add the calendar to the ldesc:calendar : fixeditem, readable location = startroom noun = 'calendar' adjective = 'wall' sdesc = "wall calendar" ldesc = "The calendar is turned to the month of December. All the Saturdays are circled in red. " ;Let's compile and run the program:startroom : room sdesc = "Fireplace" ldesc = "You are standing in front of a brick fireplace. Above the fireplace is a dusty mantle. A wall calendar hangs over the mantle. " ;As you can imagine, mixing and matching different classes can be a powerful tool, but can result in very odd and confusing behavior if used improperly. For now, just be aware of this possibility, and with experience and experimentation you'll gradually learn what classes can be safely combined.Fireplace You are standing in front of a brick fireplace. Above the fireplace is a dusty mantle. A wall calendar hangs over the mantle. You see a party invitation and an autographed photo here. >LOOK AT THE CALENDAR The calendar is turned to the month of December. All the Saturdays are circled in red. >READ THE CALENDAR The calendar is turned to the month of December. All the Saturdays are circled in red. >GET THE CALENDAR You can't have the wall calendar.
Exercise
Feel free to type in exercise3.t if it will help you learn and remember the concepts presented here. Once you feel you understand how to decorate your rooms, add decoration and readable items to the world you created in home1.t, or if you wish, start from scratch with new rooms and decorate accordingly. When you finish, continue playing "The Plant."See the Sample Source Code
Go on to Lesson Four
Go Back to Lesson Two
See the Table of ContentsThe Text Adventure Development System
Version 2.2
This page is part of Mark Engelberg's TADS Tutorial
Copyright © 1999 Mark Engelberg