Object Kinds by Brady Garvin


When Object Kinds is included, we can treat the kinds of objects as values in their own right. Ordinarily we write these values using the syntax

the object kind for (K - a kind name in the plural)

For instance,

showme the object kind for things;

will print

Object Kind #2

because "thing" is the third kind defined by Inform ("object" is Object Kind #0, and room is Object Kind #1). We can also write kinds by number, though this is less usually useful:

showme Object Kind #2;

will give the same output.

In the latter case, it may be useful to test

if (K - an object kind) is valid:
    ....

or

if (K - an object kind) is invalid:
    ....

because the extension's other phrases are liable to produce error messages if we give them an object kind that doesn't actually exist.

Other ways to obtain object kinds are via the loop

repeat with (I - a nonexisting object kind variable) running through object kinds:
    ....

or by asking an object for its kind:

the object kind of (O - an object)

Once we have a kind, we can get its parent, which is its direct superkind, or "object" if none exists:

the parent of (K - an object kind)

as well as a list of its children (its direct subkinds):

the children of (K - an object kind)

It is also possible to test whether an object has a certain kind via the being of the kind relation. For instance:

if (O - an object) is of kind (K - an object kind):
    ....

And we can say the preferred singular and plural forms:

say "[the singular of (K - an object kind)]"

say "[the plural of (K - an object kind)]"

Example: * Object Kinds Demonstration - Printing a summary of the story's kind hierarchy.

"Object Kinds Demonstration"

Include Object Kinds by Brady Garvin.

There is a room.
A pteranodon is a kind of animal; a military-grade flying hamster ball is a kind of device.
Fido is a pteranodon.
When play begins:
     say "Object kind of the player: [the singular of the object kind of the player].";
     say "Object kind of pteranodons: [the singular of the object kind for pteranodons].";
     repeat with I running through object kinds:
         say "[the singular of I] / [the plural of I]: kind of [the singular of the parent of I].[line break] Children kinds: ";
         let child printed be false;
         repeat with J running through the children of I:
             say "[if child printed is true], [end if][the singular of J]";
             now child printed is true;
         if child printed is false:
             say "(none)";
         say ".[line break] Whether the player is of this kind: [whether or not the player is of kind I].[line break]";
         say " Instance things: [the list of things that are of the kind I]."