| 4.9. Using new kinds of value in properties |
It turns out to be very useful to create a new kind of value, and then create a property to hold it. So useful, in fact, that Inform provides two shortened forms for doing so. Here is the first, and the second (making "conditions") is in the section following.
Suppose we go back to our example of the candle lantern whose brightness we have to measure. It's clear that what we want to do is to define:
Brightness is a kind of value. The brightnesses are guttering, weak, radiant and blazing.
And now we can use the technique of the previous section:
The lantern has a brightness called the flame strength. The flame strength of the lantern is blazing.
This works very nicely. The "flame strength" property is now only allowed to have one of four values we allowed: guttering light, weak light, radiant light or blazing light. So we have succeeded in recording our measurement.
But it seems artificial to call the brightness of the lantern "flame strength", when we could instead simply call it "brightness". Much simpler to write:
The lantern has a brightness. The lantern is blazing.
Now "brightness" is the name of both the property and the kind of value. What's particularly nice is that we can now use the names of the possible brightnesses - "weak", "blazing" and so on - as adjectives. Inform knows that "The lantern is blazing" must be talking about the brightness property, because "blazing" is a brightness.
Now we can improve our dead ends:
A dead end is a kind of room with printed name "Dead End" and description "This is a dead end, where crags in the uneven rock are caught by the [brightness of the lantern] flame you hold aloft. Despite [river sound] there is no sign of the stream." A dead end is usually dark.
The "[brightness of the lantern]" is printed not as literal text, but as whatever the brightness currently is. (The square brackets mark it as what is called a text substitution, which will be the subject of the next chapter.) So we get something like this:
This is a dead end, where crags in the uneven rock are caught by the blazing flame you hold aloft. Despite a faint whispering of running water there is no sign of the stream.
So now we have a lantern, which has a brightness as a property. But we can build on this further if we like. A brightness such as "guttering" is a value, so it can have properties in its own right. That can be quite useful, in fact:
A brightness can be adequate or inadequate. A brightness is usually adequate. Guttering is inadequate.
This is convenient because it divides up the brightnesses:
The player carries a book. The description of the book is "[if the brightness of the lantern is adequate]Many secrets are now yours.[otherwise]No, the print's too tiny by this awful light."
And while we're at it, let's give each brightness its own corresponding temperature:
Temperature is a kind of value. 100C specifies a temperature.
A brightness has a temperature. The temperature of a brightness is usually 700C. The temperature of blazing is 1400C. The temperature of radiant is 1100C.
The description of the lantern is "The lantern shines with a flame at [temperature of the brightness of the lantern]."
(Candle flames are hotter than most people think.)
See Text with substitutions for more on varying what is printed
| Example The Undertomb 1 A small map of dead ends, in which the sound of an underground river has different strengths in different caves. | |
When you see a long object, you don't have to think that it is too long if being long is the property given by the nature. It is proved by the fact that a duckling, having short legs, will cry if you try to draw them out by force, and that a crane, having long legs, will protest you with tears if you try to cut them with a knife. -- Zhuangzi
Suppose we have an extremely detailed world model in which every object is characterized by many features -- in this example, material and height, though one could add more. Suppose further that we would like to generate descriptions of these things automatically for the most part, drawing the player's attention only to those aspects of the object that are particularly interesting.
"The Crane's Leg"
Material is a kind of value. The materials are wood, glass, stone, cloth, paper, clay, and metal. A thing has a material.
A height is a kind of value. 3 feet 11 inches specifies a height. A thing has a height. Definition: a thing is tall if its height is 6 feet 0 inches or more. Definition: a thing is short if its height is 2 feet 0 inches or less.
So far, we have generally dealt with cases where the property of a thing can be a number (such as 3), a value (such as brightness), or a unit (like height, here). It is also possible for a thing to have a property which names another thing, as in "The mother of the baby trout is the large trout" -- where "mother" is a property, and its value, in the case of the baby trout, is large trout. We would define such a property with a line such as "A fish has a thing called the mother."
In practice, though, this is a bit confusing as syntax; moreover, Inform has a much more powerful construct for talking about the ways in which one object relates to another object. A full discussion of this will have to wait for the chapter on Relations. For now, it is enough to say that we can do this:
Imitation relates various things to one thing (called the ideal). The verb to imitate (it imitates, they imitate, it is imitating) implies the imitation relation.
This will allow us to declare that some objects imitate other objects, like so:
A chair is a kind of supporter. A chair is always enterable. A chair is usually wood. The height of a chair is usually 4 feet 0 inches. The ordinary chair is a chair. Every chair imitates the ordinary chair.
A table is a kind of supporter. A table is usually wood. The height of a table is usually 3 feet 8 inches. The ordinary table is a table. Every table imitates the ordinary table.
A rock is a kind of thing. A rock is usually stone. The ordinary rock is a rock. Every rock imitates the ordinary rock. The height of a rock is usually 0 feet 3 inches.
A jug is a kind of container. A jug is usually clay. The ordinary jug is a jug. Every jug imitates the ordinary jug. The height of a jug is usually 0 feet 8 inches.
Now each of these types has one ideal representative which has the fundamental attributes of its kind: the ordinary chair is the most chairlike chair imaginable, the ordinary table is the epitome of tableness, and so on. We are also allowed to refer to "the ideal of the chair", thanks to the way we defined imitation. (Again, the relations chapter offers a much more detailed explanation of how relations may be defined.)
The description of a thing is usually "[comparison with ideal][run paragraph on]".
To say comparison with ideal:
let the sample be the ideal of the noun;
if the sample is not a thing:
say "Perfectly conforming to your expectations of its type.";
rule succeeds;
if the material of the noun is not the material of the sample:
if the height of the noun is not the height of the sample:
if the noun is shorter than the sample, say "Unusually short at [height of the noun], and made of [material of the noun].";
otherwise say "Unusually tall at [height of the noun], and made of [material of the noun].";
otherwise:
say "Distinct mostly in being made of [material of the noun].";
otherwise:
if the height of the noun is not the height of the sample:
if the noun is shorter than the sample, say "Unusually short at [height of the noun].";
otherwise say "Unusually tall at [height of the noun].";
otherwise:
say "In every respect [a sample]."
The Pleasure Garden is a room. "At the riverbank, a pleasing garden, having many curving paths and one straight."
The low table is a table in the Pleasure Garden. The height of the low table is 2 feet 3 inches. On the low table is a metal rock called a gold nugget.
Test me with "x table / x nugget".
So far the effect is not very deep, but we could take the auto-description a great deal further: providing a larger and more interesting set of variations; or writing a complicated set of rules such that the player only notices height variations when carrying a ruler; or switching between several player-characters, each of whom notices a different subset of characteristics. But these refinements would require more input from later chapters.
|