| Chapter 4: Kinds |

| 4.7. New value properties

Moving on to properties which contain values, such as the "matching key" property of a door or a container, we need to use a different formulation.

> A dead end has some text called river sound. The river sound of a dead end is usually "a faint whispering of running water". The Tortuous Alcove has river sound "a gurgle of running water".

The property "river sound" is now applicable only to dead ends, and we would not be allowed to talk about it in any other context. As can be seen, it holds a piece of text. If we tried the following:

> The river sound of the Tortuous Alcove is 7.

...then Inform would object, because the number 7 is the wrong kind of value to go into the "river sound" property. If we need a numerical property, we can try this instead:

> A dead end has a number called the difficulty rating. The Tortuous Alcove has difficulty rating 7.

Suppose that we were to add:

> The Exquisitely Narrow Defile is a dead end.

The Defile must have a river sound, of course, because we said that every dead end would have one. But we haven't specified it. What Inform does is to start off the property holding the "default value" for this kind of value: that is, it sees that the river sound has to be "some text", and it fills in the default value for text: which is the empty text, consisting of no words at all, and written "". Similarly, its difficulty rating is set to 0. (A table of the kinds which can be used for properties, and their default values, can be found in the Kinds index.)

44
| Example Would you...? Adding new properties to objects, and checking for their presence.

For instance, if we want to give some objects a flavor: "Would you...?" The House is a room. The mouse is an animal in the House. The player carries some green eggs and a ham. A food is a kind of thing that is edible. Food has some text called flavor. The flavor of food is usually "Tolerable." Things are, in general, not edible by default, so we have to make them edible specifically in order to allow them to be eaten by the player. Here we've defined food to be edible by default, and we have given it a standard piece of flavor text. The ham and the green eggs are food. The flavor of the green eggs is "Delicious!" After eating something: if the noun provides the property flavor, say "[the flavor of the noun][paragraph break]"; otherwise say "It's [noun]-flavored." Note that we use "if the noun has a flavor..." to make sure that the property exists before attempting to use it. Otherwise, there is the risk that we will try to print a property that does not exist, resulting in errors in the game. We will only get the "It's [noun]-flavored." response if we successfully eat something that is not a food and does not have flavor text. To test this feature, let's suppose something that isn't exactly food but can theoretically be chewed on: The player carries some paper. The paper is edible. Test me with "eat ham / eat green eggs / eat paper".

45
| Example Straw Boater Using text properties that apply only to some things and are not defined for others.

Previous | Contents | Next