DEV website instance!ObjectsThe vocabulary definitions we have so far contain only verbs, but the game will obviously need nouns as well. These are mostly added via object and place definitions. So here's the first object definition: object HOOK %A small brass hook is screwed to one wall. &It is just a small brass hook[/ with a cloak hanging on it]. This defines an object and names it HOOK. By default, object names are automatically added to the player's vocabulary, so that names can be used (synonymously, if there is more than one) both by the player and by game's code. If for whatever reason some object name is to be excluded from the vocabulary, this is achieved by prefixing the name with a minus sign. An OBJECT declaration line is optionally followed by up to three kinds of object description: an inventory one, a long "here-is" one and a detailed one. The first two are displayed by the SAY directive (we'll get to it later on), depending on whether the object is carried by the player or is just present in the current location. The detailed description can be shown by the DESCRIBE directive, which is used to show the most detailed description available. In this case the hook can never be picked up by the player, so its definition omits the inventory description, which would have consisted of line(s) of text immediately following the OBJECT declaration line. The "here-is" description starts with a line prefixed with the % sign and can also consist of several text lines. Finally, the detailed description is signalled by the & sign at the beginning of a line and can also feature additional lines. In the hook's case, the detailed description contains a "text switch", which will display different text fragments depending on the internal state of the object. (All declarative features of A-code texts are covered at some length by relevant section of A-code documentation). If the hook's state has its default value of zero (or for that matter if it is negative), the description will read "It is just a small brass hook.". If it's internal state is 1 (or higher), the description will include the cloak. We could give these two values symbolic names for code clarity, but I'll leave that for an advanced tutorial. Now for the cloak... object CLOAK A velvet cloak[ (worn)/] %A black velvet cloak [/lies on the floor/hangs on the hook]. &It is a handsome cloak, of velvet trimmed with satin, and slightly spattered with raindrops. Its blackness is so deep that it almost seems to suck light from the room. This object does have an inventory description, which depends on the object's state, as does the long, "here-is" description. The cloak will have three states, which again could have symbolic names: worn, not worn (can be either carried or lying on the floor) and hanging on the hook. Finally, the specification says that there are three objects altogether, the message in the bar being the third one. Here it is, but I'll postpone its explanation until later. For the moment, just note that it has just one description with a couple of text switches. object MESSAGE The message[ has been carelessly trampled, making it difficult to read. You can just distinguish the words/, neatly marked in the sawdust, reads]... +YOU HAVE [LOST/WON] !!! That's it for objects. Next come locations.
|