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.

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).

This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...