I7: Setting values from other values

Inform 7 returns an error forbidding you to set one value equal to another (ie, “the ID number of the key is the ID number of the door”). Any way to work around this? Specifically, I want some clear bottles to have a color that’s the same as the color of the contents.

There’s a couple ways to do this. One is to not assign an official color to the bottle at all, and just have it “borrow” the color of its contents. (That’s what I did in the example below.) Alternately, you could have a color for the bottle, and have the game check when it “says” the color of something to make sure that it’s got it right.

I find the first more intuitive and easier to remember.

Here’s an example that just has transparent bottles borrow colors from their contents, but only if the contents are of a special kind (cola).

[code]Color is a kind of value. Normal colored, clear, red, blue, green, purple, and yellow are colors.

The Factory is a room.
A bottle is a transparent container in the factory. Some sparkling cola is a kind of thing. The indefinite article of a sparkling cola is usually “some”. There is some sparkling cola in the bottle. Sparkling cola has a color called hue.

The description of a sparkling cola is usually “Sparkling and [hue of item described]!”

Before printing the name of a bottle:
say "[color of the item described] ";

When play begins:
repeat with N running through the list of sparkling colas:
now the hue of N is a random color;

To decide what color is the color of (target - a container):
if the target is transparent and the target encloses a sparkling cola:
decide on the hue of a random sparkling cola enclosed by the target;
otherwise if the target is transparent:
decide on clear;
otherwise:
decide on normal colored;[/code]

If it’s a special, one-time occasion, you can always force the value change within a rule, ie “Instead of rubbing the marker on the paper: now the color of the paper is the color of the marker.”

You mean you want the color of the bottle to always be the color of the contents?

If you’ve already set up color to be a property of the bottles, the best approach is probably to adjust the bottle color after every action that changes the contents. (E.g, “now the color of B is the color of the contents of B.”) Properties can’t be based on logic; they can only be set with “now”.

If the contents of the bottles never change, you could do this once when play begins and then leave it alone for the rest of the game.

You might be able to get what you want using a relation, instead of a property. See chapter 13.12.

I’m making the contents a substance rather than an actual thing. Why doesn’t gravel’s decide statement work in that context?

[code]Color is a kind of value. Normal colored, clear, brown, and purple are colors.

A thing has a color.

Contents is a kind of value. Contents are defined by the Table of Cola.

Table of Cola
Contents Color
cola brown
grape purple
lemon-lime clear

The Factory is a room.
A bottle is a kind of container. It is transparent and openable. A bottle has a contents.

Rule for printing room description details of a bottle: stop.

In the Factory is a grape bottle.

Before printing the name of a bottle:
say "[color of the item described] ".

To decide what color is the color of (target - a container):
decide on the color of the contents of the target.[/code]

This screwed with me too. The problem is that the item described doesn’t have a color, the contents of the item described does. Try this:

Before printing the name of a bottle: say "[color of the contents of the item described] ".

Right, but the whole question is how to set the color to be the color of the contents and why this statement doesn’t work:

To decide what color is the color of (target - a container): decide on the color of the contents of the target.

Sorry, I missed this last part of your code:

This is a more subtle error. You’ve created a definition of color as a kind of value which is a property of certain contents (another KOV), and then a new definition based on a calculated value using the above code. Mixing setable properties and calculated values causes a namespace clash. You could try this:

[code]To decide what color is the hue of (target - a container):
decide on the color of the contents of the target.

Before printing the name of a bottle:
say "[hue of the item described] ".[/code]