Chapter 11: Phrases
11.16. The value after and the value before

Arithmetic is fundamental to most systems for computer programming: with Inform that is less true, so we only now come to the first mention of the addition of numbers. As might be expected, "+" can be used to combine two number values into one:

change the score to the score + 4

(This can also be spelled out "plus": or we could have written "increase the score by 4". Similarly, we can "decrease".) Inform generally expects to apply addition only to two numbers, so we cannot normally apply "+" to values like these:

Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.

There will be more about arithmetic on new kinds of value in the chapter on Units, but it may be useful to note that although we cannot (ordinarily) add up colours, we do automatically have two ways to make new colours from old:

the colour after C
the colour before C

produce the next, and the previous colour respectively, in order of their declaration. Thus "the colour after red" is orange; "the colour before blue" is green. The values wrap around, that is, "the colour before red" is violet and "the colour after violet" is red.

We are also allowed to use number-like comparisons with new kinds of value. Thus "red < yellow" is true, while "green >= violet" is not. Again, more on comparisons in the chapter on units.


168
* Example  Entropy
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).

RB

"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
    begin;
        if the heat of the item is greater than room temperature, change the heat of the item to the heat before the heat of the item;
        if the heat of the item is less than room temperature, change the heat of the item to the heat after the heat of the item;
    end repeat.

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
    begin;
        if the ice cube is visible, say "The ice cube melts! 'HA ha,' says Maxwell, in a very unsporting, some might say demonic, way.";
        remove the ice cube from play;
    end if.

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
    begin;
        say "Maxwell sadly stabs at his leftovers with a chopstick, but does not try to eat any more.";
        move the food to the location;
    end if.

Test me with "z / z / open thermos / close thermos / open thermos".

169
*** Example  The Hang of Thursdays
Turns take a quarter day each, and the game rotates through the days of the week.

RB


PreviousContentsNext