Inform 7 Home Page / Documentation
§15.16. Understanding specified numbers
It may be worth noting in passing that number specifications, like all other kinds of value, can be understood in typed commands. (See the chapter on Understanding for more on what can go in such square brackets.) For instance:
"America Stands Tall"
The Oval Office is a room. Josh and Toby are men in the Oval. A height is a kind of value. 5 foot 11 specifies a height. A person has a height. Josh is 5 foot 8. Toby is 5 foot 10.
Height guessing is an action applying to one thing and one height. Understand "guess [someone] is [height]" as height guessing.
Check height guessing: if the noun is not a person, say "You can only guess the height of people." instead. Carry out height guessing: if the height of the noun is the height understood, say "Spot on!"; if the height of the noun is greater than the height understood, say "No, [the noun] is taller than that."; if the height of the noun is less than the height understood, say "No, [the noun] is shorter than that."
Test me with "guess josh is 6 foot 3 / guess josh is 5 foot 9 / guess josh is 5 foot 3 / guess josh is 5 foot 8".
|Start of Chapter 15: Numbers and Equations|
|Back to §15.15. The parts of a number specification|
|Onward to §15.17. Totals|
Understand the command "cut" as something new. Understand "cut [length] from/off [something]" as trimming it by (with nouns reversed). Understand "cut [something] by [length]" as trimming it by. Understand the command "trim" as "cut".
Check trimming it by:
if the length understood is 0 inches, say "You're approaching Zeno's string at this point." instead;
if the length understood is greater than the length of the noun, say "[The noun] is only [length of the noun] long to start with." instead;
if the length understood is the length of the noun, say "[The noun] is already exactly [length of the noun] long." instead.
Carry out trimming it by:
now the length of the noun is the length of the noun minus the length understood;
let the other half be a random string in the string repository;
now the length of the other half is the length understood;
move the other half to the player.
Report trimming it by:
reset string lengths; [we will define this in a moment; it helps guarantee that our descriptions of the strings are correct when we write the output list]
say "You now have [a list of strings carried by the player]."
This fudges slightly, since an odd-length string will be divided into uneven halves. Keeping track of fractional inches would complicate matters, though, so let's assume for now that this doesn't matter.
Since our initial string is 36 inches long and it is impossible for the player to divide it into pieces smaller than an inch each, we need a total of 36 items to represent all the string-bits: one that the player carries at the outset, and 35 others. We should bear in mind that it is usually a good idea to use the smallest number of spare objects we can get away with: writing a game that required 1000 strings in the string repository would place silly demands on the resources of the system, so it's best to avoid that sort of thing if possible.
Now with a bit of fiddling we can also teach Inform to recognize descriptors such as "the shortest string":
To reset string lengths:
let upper measure be the length of the largest visible string;
let lower measure be the length of the smallest visible string;
repeat with item running through strings:
now the ordinariness of the item is medium;
if the length of the item is the upper measure, now the item is longest;
if the length of the item is the lower measure, now the item is shortest.
Instead of tying a string to a string:
move the second noun to the string repository;
now the length of the noun is the length of the noun plus the length of the second noun;
decrease the length of the noun by 1 inch;
say "You end up with [a noun], as some is taken up by the knot."
This is still a little incomplete because we cannot refer to strings by their lengths, as in "the 2 inch string" and so on. To do this, we borrow a line from the chapter on Understanding: