Chapter 11: Phrases
11.18. 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.


181
* 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
182
*** Example  The Hang of Thursdays
Turns take a quarter day each, and the game rotates through the days of the week.

RB

"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:
        change the current time period to the time period after the current time period;
    otherwise:
        change the current time period to morning;
        change the current weekday to 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".


PreviousContentsNext