Adding an Object to the Room
|
It is time we added an object to our sample game. If you run the game again and try typing examine cottage you'll be told that:
|
|
|
vocabWords = 'pretty little cottage/house/building'
name = 'pretty little cottage'
desc = "It's just the sort of pretty little cottage that townspeople
dream of living in, with roses round the door and a neat little
window frame freshly painted in green. "
location = outsideCottage
;
|
|
|
'pretty little cottage' @outsideCottage
"It's just the sort of pretty little cottage that townspeople dream of living in,
with roses round the door and a neat little window frame freshly painted in green. "
;
|
|
|
'pretty little cottage'
"It's just the sort of pretty little cottage that townspeople dream of living in,
with roses round the door and a neat little window frame freshly painted in green. "
;
|
|
'pretty little cottage'
"It's just the sort of pretty little cottage that townspeople dream of living in,
with roses round the door and a neat little window frame freshly painted in green. "
;
|
|
+ desk : Heavy, Surface 'desk' 'desk' "This large desk has a single drawer. ";
++ drawer : Component, OpenableContainer 'drawer', 'drawer' "It looks like it should open easily. ";
+++ redPencil : Thing 'red pencil' 'red pencil' "It's a bit blunt. ";
+++ bluePencil: Thing 'blue pencil' 'blue pencil' "It's been sharpened recently. ";
In this case both the red pencil and the blue pencil will be inside the drawer, the drawer inside the desk, and the desk inside the study.
|
The problem here is that Thing is the most generic class of object in the library. For objects that you want the player character to be able to pick up and carry around it's often fine, but for things that are fixed in place or otherwise not intended to move, it's not the best class to use. We could use the Fixture class to fix the present example. Try changing Thing to Fixture in the definition of cottage and recompiling the game. Then run it again. You'll see that the game no longer displays "You see a pretty little cottage here" and that you can no longer pick the cottage up. This is just about what we want (at least for now), but there's a couple of further refinements we could add.
Firstly, the main reason for adding the cottage was that a cottage was mentioned in the room description, so the player ought to be able to refer to it. So far, we have no other use for the cottage object. In effect, the cottage is purely decorative, part of the scenery but not otherwise part of the game. For this purpose the library defines a Decoration class, and that might be the one to use here.
Secondly, since the cottage is purely decorative (at least at this stage) we probably won't need to refer to it anywhere else. We can therefore make it an anonymous object, i.e. one to which we do not give an object name. Such an object can simply be defined with its superclass name (or list). So we can finally redefine our cottage as follows:
|
"It's just the sort of pretty little cottage that townspeople dream of living in,
with roses round the door and a neat little window frame freshly painted in green. "
;
|
You'll note that the description of the cottage includes a door, a window and some roses. It's always possible that a player may try to examine these; so as an exercise you could try adding further Decoration objects to represent them.
In the present chapter we have learned the basics of defining room objects and other objects. Progress may have seemed slow, but these are the basics that apply to all objects in the game, so we should be able to make more rapid progress from now on. In the next chapter we'll make our game a little more interesting by adding some more rooms and objects.
Getting Started in TADS 3
[Main]
[Previous] [Next]