Incrementing named values

In the 2009 edition of the Handbook, I recommended using syntax like this:

[code]Brightness is a kind of value. The brightnesses are guttering, weak, radiant, and blazing.
A brightness can be adequate or inadequate. A brightness is usually adequate. Guttering is inadequate.

A lamp is a kind of thing. A lamp has a brightness. The brightness of a lamp is usually radiant. The table lamp is a lamp.

After jumping:
increase the brightness of the table lamp by 1;
continue the action.[/code]
The first bits are directly from Writing with Inform, and work fine. But the “increase the brightness” line no longer works. The compiler complains:

Problem. You wrote 'increase the brightness of the table lamp by 1', but 'brightness of the table lamp' is supposed to be a stored value holding a brightness, so it cannot be set equal to 1, whose kind is a number.

Skimming through chapter 4 of Writing with Inform, I’m unable to spot a convenient syntax for adjusting a named value up or down. What is the current method of doing this?

It looks like you want this syntax from §11.18 of writing with Inform:

Now the brightness of the table lamp is the brightness after the brightness of the table lamp

which could be made more legible with temporary variables, if you like (“let the new brightness be the brightness after the brightness of the table lamp”).

Thanks – that works. However, it does operate on the values as if they were stored in a circular array. The brightness after radiant is guttering. Seems to me an author would be better off writing a manual rule for this type of situation, so as to pin the value when it reaches a maximum or minimum.

There may be no general way to do that, because the number of named values could be different for different values. Is there a way to test how many brightnesses there are?

I don’t know, but you can test to see if it’s the “last value of brightness.” So you could roll up a phrase that doesn’t loop, like this:

To increment the brightness of (item - a thing): unless the brightness of the item is the last value of brightness: now the brightness of the item is the brightness after the brightness of the item.

I had hoped to be able to use kind variables (22.7) to write a general phrase for any value, which returns the next value without wrapping, like this:

To decide which K is the capped successor to (original - enumerated value of kind K): if the original is the last value of K: decide on the original; otherwise: decide on the K after the original.

but “last value of K” isn’t compiling, alas (and is causing weird errors in the standard rules).

…looking at the phrases the Standard Rules use to handle this, maybe I need to get “name of kind of enumerated value K” in there somehow? Not sure how to do it.

I have no idea why, but you can avoid the compilation errors by breaking “the last value of K” off into a local variable:

To decide which K is the capped successor to (original - enumerated value of kind K):
	let the last be the last value of K;
	if the original is the last:
		decide on the original;
	otherwise:
		decide on the K after the original.

This then appears to work as desired. You may want to submit a bug report about your original version not working though - it’s unclear why this version is any more valid. And at any rate the Problem messages your version produced are entirely unhelpful.

Thanks! Reported.