Login
Remember
IF Answers
Ask a Question

# Is it possible to make kinds of kinds of values in inform 7?

+1 vote
193 views
asked Jun 22 in Authoring by anonymous

I want to do something like this:

    A measurement is a kind of value.
    A waist size is a kind of measurement.

Sadly, ni returns this problem:

    You wrote 'A waist size is a kind of measurement' ...
    but you are only allowed to create kinds of objects
    (things, rooms, and so on) and kinds of 'value' ...

I take from this that it isn't possible to specialize values by making kinds of kinds of values? How can I accomplish something similar? My end goal is to make a property that can contain values from any of a certain set of kinds of values.

- inform7
- values
- kinds

commented Jun 23 by Joseph Geipel (207 points)
Do you want to accomplish something along the lines of making a property that can be either a number or a truth state?
commented Jun 24 by anonymous
No, I want a property that can be either a 'waist size' or a 'batting average', both of which are values.

## 1 Answer

+1 vote
answered Jun 27 by vaporware (56 points)

This isn't supported, but there are probably other ways to achieve what you're looking for.

The way a value is interpreted depends on its type: to be able to print a measurement correctly, you have to know its type, and to be able to compare two measurements, you have to know whether they have the same type.

But user-created kinds of value always occupy a single machine word. The waist size "31 inches", the batting average ".031", and the hat size 31 might all be represented by the same integer value in the compiled game. There's no place inside a measurement to keep track of what subtype it is.

Some alternatives are:

1. Make measurement a kind of object. This gets you subtyping, but it means you have to define a fixed number of measurements (of each subtype) at compile time.

2. Use two properties. One is a type code ("The measurement types are weight, batting average, ...") and the other is a generic number whose interpretation depends on the type code.

3. Use two-element lists. As above, the first element is a type code, and the second is a generic number. This makes the measurement values easier to pass around, but since all the values in a list have to be the same type, the type code will have to be a number (you can define variables or phrases to give the type codes names).

## Related questions

- In Flexible Windows, is it acceptable to set, e.g., the window position at or after the start of play? (Inform 7)
- With Flexible Windows by Jon Ingold, is there a way to make the text display at the top of the window, even in Gargoyle? (Inform 7)
- How do I move an item I have more of in the world (since it's a kind of thing)?
- When using hyperlinks, how do you make the command appear appear next to the > instead of on the following line? (Inform 7)
- How to make the player specify which thing of a kind they mean? (Inform 7)

...