A TADS Tutorial: Lesson Four
More Items
Review
In Lesson 3, you learned that the TADS language has many useful classes that make it easy to program certain types of objects. The room class is one that you are already familiar with from Lessons 1 and 2, and in Lesson 3 the decoration class, readable class, and fixeditem class were introduced.You've now seen several examples of how to create an object of a given class; here's a quick reminder of how it works in general. You always start by giving the object a programming name, and then a colon, and then the name of the class or classes that the object will get its behavior from. Then you assign values to the properties that are relevant for that object. The description of the object must always end with a semicolon. So the code will always look something like this:
With all of the objects you've created so far, you've needed to give values for sdesc (short description) and ldesc (long description). You also found that some classes supported certain properties that others didn't. For example, room supports properties for directions like north, south, east, and west, while decoration, readable and fixeditem support properties like location, noun, and adjective (which define where an item is located and what words can be used to refer to it within the game).objectname : classname propertyname = propertyvalue ;
Exercise Four
Today's lesson will introduce several new classes, accompanied by short examples that demonstrate what properties need to be defined for objects derived from that class. In the first few lessons, I encouraged you to type in the programming examples verbatim, but this time, I'd like you to just use the sample program fragments as a reference for you to program your own examples. In fact, you don't need to program an example of every single class discussed here, just pick several that interest you and try them out. Use your imagination, and experiment freely with the classes discussed in this lesson.Remember, capitalization is important. Type the class names exactly with the given capitalization.
It is worth keeping in mind that all of the behavior of these classes can be customized, and new classes can be created. We will be looking at how to do this in future lessons. In the meantime, enjoy the many possibilities that these classes already offer.
As you create your own examples, remember from Lesson 3 that takeable items are automatically listed as part of the room description; but permanent, immovable objects are not, and must be explicitly mentioned as part of the room's ldesc.
distantItem
This class works a lot like the decoration class, and in fact, the properties are exactly the same. It is intended to be used for decorations that are too far away to touch. When a user tries to do anything but "LOOK AT" a decoration, he gets the message "It isn't important." However, when a user tries to do something to a distantItem, he gets the message "It's too far away."mountains : distantItem location = startroom noun = 'mountain' 'mountains' sdesc = "mountains" ldesc = "The mountains are beautiful, but are far, far away. " ;
seethruItem
This class should be used for things like windows that the user can "LOOK THROUGH." A seethruItem object needs to have a message assigned to the thrudesc property. This message should describe what the player sees when he looks through the object. By default, a seethruItem is takeable, so if you don't want the object to be moveable, you'll need to also make it a fixeditem.magnifyingGlass : seethruItem location = startroom noun = 'glass' adjective = 'magnifying' sdesc = "magnifying glass" ldesc = "It looks like a standard, handheld magnifying glass." thrudesc = "When you look through the magnifying glass, everything looks much bigger. " ; window : seethruItem, fixeditem location = startroom noun = 'window' sdesc = "window" ldesc = "A double-paned window provides a pleasant mountain view." thrudesc = "As you look through the window, you sigh at the beauty of the mountains outside. " ;
chairitem
Objects derived from this class act like a chair. Players can sit on a chairitem object, and while sitting on it, they can't go anywhere or reach anything until they stand up again. A chairitem can not be moved by the player, so it should be mentioned explicitly in the room's ldesc.comfyChair : chairitem location = startroom noun = 'chair' adjective = 'comfy' sdesc = "chair" ldesc = "The comfy chair has an indentation in the seat from many years of supporting your butt. " ;
beditem
Objects derived from this class act like a bed. Players can sit or lie on a beditem object, and they can't go anywhere or reach anything until they stand up again. A beditem can not be moved by the player, so it should be mentioned explicitly in the room's ldesc.waterbed : beditem location = startroom noun = 'bed' 'waterbed' sdesc = "waterbed" ldesc = "The king-size waterbed takes up most of the room. " ;
fooditem
Use this class to create objects that can be eaten. Once the object is eaten, it is removed from the game. Many games require players to find and eat food every so often, or else die of starvation.candybar : fooditem location = startroom noun = 'bar' adjective = 'candy' 'chocolate' sdesc = "chocolate bar" ldesc = "The bar of chocolate is unwrapped. It's amazing it hasn't turned into a sticky, gooey mess. " ;
clothingItem
Use this class to create objects that can be worn or taken off.ring : clothingItem location = startroom noun = 'ring' adjective = 'secret' 'decoder' 'plastic' sdesc = "ring" ldesc = "This is the plastic secret decoder ring that you found in your box of Cheerios yesterday at breakfast. " ;
surface
Objects can be placed on a surface object (for example, to allow a player to type "PUT THE KNIFE ON THE DESK," the desk needs to be a surface). By default, the surface itself can be taken and dropped. To make the surface object immovable, you must also make it a fixeditem (see the section on multiple inheritance in Lesson 3 for a similar example). Do not set the ldesc property; it will automatically be set to describe what is on the surface.If you want an item to start out on a surface, just set its location property to the surface, instead of the room.
desk : surface, fixeditem location = startroom noun = 'desk' sdesc = "desk" ;
container
Objects can be placed in a container object (for example, to allow a player to type "PUT THE BALL IN THE BAG," the bag needs to be a container). By default, the container itself can be taken and dropped. To make the container object immovable, you must also make it a fixeditem (see the section on multiple inheritance in Lesson 3 for a similar example). Do not set the ldesc property; it will automatically be set to describe what is in the container.If you want an item to start out in the container, just set its location property to the container, instead of the room.
pencilHolder : container location = desk noun = 'holder' adjective = 'pencil' sdesc = "pencil holder" ;
openable
An openable object is just like a container, but it can be opened or closed. When the object is closed, the player can't see what's inside. The property isopen must be set to either true or nil (which means false) to determine whether the object starts off open or closed. Do not set the ldesc property; it will automatically be set to describe what is in the container.box : openable location = startroom noun = 'box' adjective = 'cardboard' sdesc = "cardboard box" isopen = nil ;
transparentItem
The transparentItem class is most useful when combined with one of the many container classes discussed here. For example, if you make an object both openable and transparentItem, then even when the object is closed, the player can still see what is inside. (See the example given after lockable.)
lockable
A lockable object is just like an openable, but not only can it be opened or closed, it can also be locked or unlocked. It doesn't actually require a key to lock and unlock the object, so this class is really only good for objects with deadbolts or some other built-in locking mechanism. The property islocked must be set to either true or nil (which means false) to determine whether the object starts off locked or unlocked. Do not set the ldesc property; it will automatically be set to describe what is in the container.jar : transparentItem, lockable location = box noun = 'jar' 'latch' adjective = 'glass' 'locking' sdesc = "glass jar with locking latch" isopen = nil islocked = true ;
keyItem
keyItem objects can be used as a key to lock and unlock objects of certain classes that will be discussed shortly.brassKey : keyItem location = closet noun = 'key' adjective = 'brass' 'big' 'shiny' sdesc = "brass key" ldesc = "It's a big, shiny, brass key. " ;
keyedLockable
A keyedLockable object is just like a lockable (so it is used for containers that can be opened and closed, and locked and unlocked), but a specific key is required to lock and unlock the object. You need to set the mykey property to the programming name for the keyItem object you have created to be the key for this object. Do not set the ldesc property; it will automatically be set to describe what is in the container.treasureChest : keyedLockable location = startroom noun = 'chest' adjective = 'treasure' sdesc = "treasure chest" mykey = brassKey isopen = nil islocked = true ;
darkroom
If you want to make a room dark, then make it a darkroom instead of a room. The player can only see inside a darkroom if there is some source of light inside the room (for example, he is carrying a lightsource object).closet : darkroom sdesc = "Closet" ldesc = "You are in a tiny closet containing a dresser and a pile of clothes. The exit is to the west." west = startroom ;
lightsource
This class is used for portable sources of light, like a lamp, candle, match, flashlight, or glowing object. To ensure that the lightsource object is activated when the player finds it, set the property islit to true. In a future lesson, we will discuss how to make it possible for the player to turn the source of light on and off.firefly : lightsource location = jar noun = 'fly' 'firefly' sdesc = "firefly" ldesc = "The firefly is buzzing and generating a surprising amount of light." islit = true ;
underHider
There are three ways to hide objects. You can hide objects under, behind, or in other objects. An underHider object can have things hidden under it. To find the hidden objects, the player will have to "LOOK UNDER" this object. By default, underHider objects can be taken, so you'll probably want to also make the object a fixedItem or some other unmovable object. (See the example given after behindHider.)
behindHider
A behindHider object can have things hidden behind it. To find the hidden objects, the player will have to "LOOK BEHIND" this object. By default, behindHider objects can be taken, so you'll probably want to also make the object a fixedItem or some other unmovable object.dresser : underHider, behindHider, fixeditem location = closet noun = 'dresser' sdesc = "dresser" ldesc = "This dresser has no drawers, and is falling apart. The dresser has short stubby legs, which create a bit of a gap between the dresser and the floor. There is also some space behind the dresser. " ;
searchHider
A searchHider object can have things hidden inside of it. To find the hidden objects, the player will have to "LOOK IN" or "SEARCH" this object. By default, searchHider objects can be taken, so you'll probably want to also make the object a fixedItem or some other unmovable object.clothes : searchHider, fixeditem location = closet noun = 'pile' adjective = 'clothes' sdesc = "pile of clothes" ldesc = "A messy pile of clothes covers the floor. Who could even guess what might be buried in the pile?" ;
item
If you want to create an object that can be taken or dropped, and the object doesn't fall into one of the specialized categories already discussed, just make the object an item. In a future lesson, we'll talk about how to program unusual capabilities into your item objects.pencil : item location = pencilHolder noun = 'pencil' adjective = 'wooden' 'wood' sdesc = "wood pencil" ldesc = "This pencil is in dire need of sharpening." ;
hiddenItem
All hidden items must be hiddenItem objects. Do not set the location property for this object. Instead, use the underLoc property to give the name of the underHider that it is hiding under, or the behindLoc property if it is hidden behind a behindHider, or the searchLoc property if it is hidden inside a searchHider. This class doesn't really work properly unless it is combined with the item class to make the object takeable once it is found.diamond : hiddenItem, item underLoc = dresser noun = 'diamond' sdesc = "diamond" ldesc = "The sparkling diamond is exquisite. You can't imagine how it could have ended up under the dresser." ; emerald : hiddenItem, item behindLoc = dresser noun = 'emerald' sdesc = "emerald" adesc = "an emerald" ldesc = "The emerald is an intense shade of green. You wonder how it ended up behind the dresser. " ; ruby : hiddenItem, item searchLoc = clothes noun = 'ruby' sdesc = "ruby" ldesc = "The ruby is blood red. What was it doing in your pile of clothes? " ;
Experiment
Now that you've seen examples of many new classes, don't forget to experiment. What other combinations might be possible?What interesting environments can you program? A haunted house, jungle, graveyard, space station, alien world, forest, swamp, airport, magical kingdom, etc.beditem, underHider hiddenItem, keyItem transparentItem, keyedLockable lightsource, keyItem container, readableSee the Sample Source Code
Go on to Lesson Five
Go Back to Lesson Three
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