A DAAD Tutorial for beginners(2)
Chapter 2
In this chapter we will talk about objects.
Objects are common to all adventure games, and are the key to solve many puzzles. You can have weapons, items to trade, tools and even useless red herrings.
We are going to have the following objects in our game:
* an iron bar
* a piece of coal
* some sheets
* a knife
* a mattress cover
We will add some texts, much like we did with locations, but in the /OTX section:
/0 "an iron bar"
/1 "a piece of coal"
/2 "some sheets"
/3 "a knife"
/4 "a mattress cover"
We are also going to add the following, just below the #defines for the locations we added in the previous chapter.
#define oBar 0
#define oCoal 1
#define oSheets 2
#define oKnife 3
#define oCover 4As you may already noticed, I use to set the label names so I know what they stand for, so the labels for locations start with an “l”, those for objects start with an “o” and those for flags start with an “f”. This is just a convention, you can name the labels as you prefer.
Ok, now we have to define the objects properties, which is done in the /OBJ section. Please fill that section with the following code:
/0 252 2 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ BAR IRON
/1 252 1 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ COAL _
/2 252 1 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ SHEETS_
/3 252 1 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ KNIFE _
/4 252 1 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ COVER _ And finally, add this to the vocabulary:
BAR 201 noun
COAL 202 noun
SHEETS 203 noun
KNIFE 204 noun
COVER 205 noun
IRON 200 adjectiveSo what’s all that for.
Obviously the OTX section contains the object description, that will be used for inventory , to say they are at some location, to be part of messages like “you take the knife”, etc.
The /OBJ section has a line per object, and then several data inside. The first value after \0 is 252. That is the initial location for the object, you can provide a location number if the object should be initially at that location, or use a label (i.e. lBarracks). Also, you can use some of the three special locations:
252: the item is nowhere, can’t be seen
253: the item is worn
254: the item is carried
Get Uto’s stories in your inbox
Join Medium for free to get updates from this writer.
So as you can see, all objects in our game are nowhere.
The next value you see is object’s weight. This is not a value in pounds or kilograms, is what you decide it to be. There is a way to set the maximum weight the player can carry, so you can decide the player can carry 10 units and then set the weight of each object according that limit, so it makes sense.
Just after that there are 18 yes/no values. You can set any of them to YES by writing an Y instead of the underscore char.
The first one, if set to yes, means the object is a container. That means DAAD will allow player put other objects inside that one. Please take in mind when a container is created, the location whose number is equal to that object number, will be used as location to contain the objects you put inside the container. That means if you are going to have container, you should leave those location numbers unused, with empty description, and no connections to them
The second one, if set to YES, means the object is wearable, you can wear it. That is usually clothes, but it may be something else, or even it’s possible to have a wearable container (i.e. a backpack).
Then there are 16 more yes/no values. They have no specific use, but DAAD allows you to check if an object has it, so you can decide what to do. For instance, you can decide the first of those 16 values means the object is edible, and when the player types “eat xxxx”, where xxxx is an object, check if the object has that value set to yes, and if so, the player can eat it.
Finally, after the 16 values, there is the noun used to refer to that object, and the adjective. Adjective is not mandatory, and although we have added “iron” in this tutorial so you can see it, they are not recommended unless you need to use them to make two objects different (i.e. the red key and the yellow key).
So now that you know how objects are defined, let’s make one of them appear. The coal can be found by examining the fireplace at the hall.
Look at the code:
> EXAMINE FIREPLACE
AT lHall
MES “The fireplace is plenty of dust and there is no fire.”
ISAT oCoal 252
MESSAGE “There is a piece of coal. You carefully give it a nudge and it falls to the floor next to the fireplace.”
CREATE oCoal
ANYKEY
RESTART> EXAMINE FIREPLACE
AT lHall
NEWLINE
DONE
We should also add the word fireplace to vocabulary
FIREPLACE 206 noun
So, how does that work?
First, as in first chapter, we check if we are at the right location (AT lHall), then we write a message describing the fireplace. This message would happen no matter if we find the coal or if we examine it again later. Please notice we use MES instead of message, that will make DAAD print the message without a carriage return at the end.
Then it comes the following condition:
ISAT oCoal 252This one will be successful if the object oCoal is at location 252 (nowhere), so the rest of the entry will not be executed if that is not true. Please notice that unlike the previous chapter entries, in this case we don’t have all conditions first, then all the action, there is a CONDITION-ACTION-CONDITION-ACTIONS sequence that allows first action to be executed before the second condition is evaluated.
Ok, if the coal is nowhere, we are going to bring it to location lHall, that is done by telling the player there is some coal there, and then using the CREATE condact, which will make the object oCoal to be placed at the current location. The player will still have to take it. Finally ANYKEY (wait for a key press) and RESTART (redescribe the location, so player can see the coal on the floor) are executed.
But what happens if the coal is not at location 252 (it was discovered before). Ok, then second entry is executed. and a NEWLINE followed by DONE are executed if we are at lHall. NEWLINE adds a carriage return, so the ide is if the coal is nowhere we will read “The fireplace is plenty of dust and there is no fire. There is a piece of coal here.” and if the coal was discovered before, then the player will see “The fireplace is plenty of dust and there is no fire.”
This is the end of second chapter, I hope you understand now properly how to work with objects.








