Inform 7 Home Page / Documentation
§11.18. The value after and the value before
A point which has come up several times in recent chapters is that enumerated kinds of value have a natural ordering. For example, if we write:
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
...then we not only have seven possible values, we have put them into a sequence, in order of their naming. We can't perform arithmetic on colours, of course, but we can perform comparisons on them. Thus "red < yellow" is true, while "green >= violet" is not. (More on comparisons in the chapter on Numbers and Equations, which also covers arithmetic.)
It's also sometimes useful to get at the sequence directly. First, the two ends:
first value of (name of kind) ... value
This phrase produces the first-created value of the given kind, which should be an enumeration. Example: if we have
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
then "first value of colour" is red.
last value of (name of kind) ... value
This phrase produces the last-created value of the given kind, which should be an enumeration. Example: if we have
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
then "last value of colour" is violet.
And now how to step forward and back:
(name of kind) after (enumerated value) ... value
This phrase produces the next-created value of the given kind, which should be an enumeration. Example: if we have
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
then "colour after orange" is yellow.
(name of kind) before (enumerated value) ... value
This phrase produces the previous-created value of the given kind, which should be an enumeration. Example: if we have
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
then "colour before blue" is green.
|
ExampleEntropy
All objects in the game have a heat, but if not kept insulated they will tend toward room temperature (and at a somewhat exaggerated rate).
|
|
"Entropy"
Heat is a kind of value. The heats are frosty, cold, cool, room temperature, warm, hot, and scalding. Everything has a heat. The heat of a thing is usually room temperature.
Every turn:
repeat with item running through things which are not in an insulated container:
if the heat of the item is greater than room temperature, now the heat of the item is the heat before the heat of the item;
if the heat of the item is less than room temperature, now the heat of the item is the heat after the heat of the item.
Definition: a container is insulated if it is closed and it is opaque.
The vacuum thermos is an opaque closed openable container carried by the player. In the vacuum thermos is a frosty thing called an ice cube.
Every turn:
if the heat of the ice cube is greater than cold:
if the ice cube is visible, say "The ice cube melts! 'HA ha,' says Maxwell, in a very unsporting, some might say demonic, way.";
now the ice cube is nowhere.
Before printing the name of something: say "[heat] ".
Equilibrium is a room. "A perfectly smooth chamber sealed from the outside world. You can't at this moment work out where the exit is, though possibly that is just because the lighting is so very very even and diffuse. And doesn't come from anywhere that you can see, either."
Maxwell is a man in Equilibrium. "Maxwell perches awkwardly on a stool across from you[if Maxwell has something], holding [a list of things carried by Maxwell][end if]." He is carrying a box of Chinese food. The Chinese food is scalding. "A discarded [item described] lies on the floor." The description of Maxwell is "He has the faintly peevish look of one who has not been properly fed."
Every turn when Maxwell has the food:
if the heat of the Chinese food is greater than warm, say "Maxwell takes a bite, and swears.";
if the heat of the Chinese food is warm, say "Maxwell eats as fast as he can, enjoying the food while it's at just the right temperature.";
if the heat of the Chinese food is less than warm:
say "Maxwell sadly stabs at his leftovers with a chopstick, but does not try to eat any more.";
move the food to the location.
Test me with "z / z / open thermos / close thermos / open thermos".
"The Hang of Thursdays"
The Stage is a room. Rule for printing the name of the stage: say "[current weekday] [current time period]" instead.
A weekday is a kind of value. The weekdays are Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday. The current weekday is a weekday that varies. The current weekday is Saturday.
A time period is a kind of value. The time periods are morning, afternoon, evening, night. The current time period is a time period that varies. The current time period is afternoon.
This is the new advance time rule:
if the current time period is less than night:
now the current time period is the time period after the current time period;
otherwise:
now the current time period is morning;
now the current weekday is the weekday after the current weekday.
Now we need to borrow from a later chapter to make these instructions apply to the passage of time:
The new advance time rule is listed instead of the advance time rule in the turn sequence rules.
Test me with "z / z / z / z / z".