# The kind of the kind

Is there a way to refer to the kind of the kind… that is, if something is a kind of thing, but all things of its kind are a kind, like a parent kind, is there a way to refer to this? Say there is a weapon kind, and then both a sword kind and an axe kind, both of which are kinds of weapon… without directly referencing the weapon kind (because this is only one example and the function will need to deal with “unexpected” kinds) how can I indicate the weapon kind for both swords and axes?

You mean like a vehicle is a kind of container, which is in turn a kind of thing?

Something like this?[code]Section “Setup”

To decide what number is kind index of (O - an object): (- ({O}.KD_Count) -).
To decide what number is the parent kind index of the kind index (I - a number): (- KindHierarchy–>({I} * 2 + 1) -).
To say (N - a number) as a kind index: (- print (I7_Kind_Name)(KindHierarchy–>(2 * {N})); -).

Section “Demo”

There is a room.
A weapon is a kind of thing; a sword is a kind of weapon; an axe is a kind of weapon.
Foo is a sword.
When play begins:
let K be the kind index of Foo;
while K is not zero:
say “[Foo]: [K as a kind index].”;
now K is the parent kind index of the kind index K.[/code]

Wow, eu, you also posted the answer to my question about saying “the kind of the noun” as well… and it also involved including I6. Thank you for both answers!

I guess, Inform 7 doesn’t “like” dealing with kinds in any non-standard way? I wish I understood your answers, instead of just having to copy/paste your work into my project. I guess I could try to learn I6 as well, but I had hoped I7 was a platform that could do what I needed it to, but it seems a lot of extensions have to go back to relying on the I6 base as well, looking at their source code.

Well, all I7 must eventually become I6. The idea, I gather, was that this I7-to-I6 interfacing would be the purview of extensions, with the Standard Rules covering the most common cases, and other situations left for the community to develop de facto standards for. So you get things like Flexible Windows, whose express purpose is to present an I6 API in I7. Add to that extensions written by authors who prefer I6, or using code from before I7 supported the things they want to do, or choosing to bypass I7 for a little performance boost, and its maybe not surprising that extensions include I6 fairly often. But the intent is that I7 plus extensions should be sufficient for story authors.

Sometimes, as here, we discover that something’s been missed out. In which case maybe the answer shouldn’t be `here, embed this cryptic I6 in your story,'' but`oh, hey, that’s not covered by an extension yet, let me fill that gap, and then you can use the extension.’’ For this case in particular, I suppose, since you’re not the first to ask about walking the kind hierarchy.

So, hey, that’s not covered by an extension yet—let me work on that and get back to you.

(Incidentally, if you do choose to learn I6 anyway, you should know about inform7.com/sources/src/i6templa … index.html. I yoinked the code above from a snippet in RTP.i6t.)

Extension here, though I see you don’t need it anymore.

I wouldn’t say that! This looks like an extension that could prove very useful. I may not have a need right at this very moment, but that’s just because I’m a noob pecking my way through… I’m sure I’ll run into a situation soon enough where dealing with kinds in ways this extension enables will be a godsend for. Thanks for making that and sharing!

Well, it’s been quite some time since you posted this extension. I’m at the point in my game that I’m trying to use it now.

I love the idea of this, but I am having some trouble using the being of kind relation. This code causes an error saying “an object kind cannot be an object”:

``````The kitchen is a room.

The player is in the kitchen.

An apple is a kind of thing.

1 apple is in the kitchen.

After taking something:
if the noun is of kind apple:
say "What is the correct syntax here?";``````

I also tried this with no luck:

``````After taking something:
if the object kind of the noun is apple:
say "What is the correct syntax here?";``````

I know the user base of this extension might just be me (although I find it hard to imagine not being able to repeat through things and check their class/kind in any program, so others could find it helpful too!), but if you are willing, please help me again with this.

Edit: Nevermind, I figured it out. Thanks for this extension!

``````After taking something:
if the object kind of the noun is the object kind of a random apple:
say "Aha!";``````

I realize this example doesn’t make much sense by itself because you can just normally say:

``````After taking something:
if the noun is an apple:
say "Aha!";``````

But I was trying to figure out the syntax for getting at the object kind from this extension because I’ll be dealing with UNKNOWN kinds. I don’t have an example of that, but I know that the rules I’m about to write will incorporate that into it, so knowing how this simple example worked was a prerequisite.

Ok, I have another question now… there are a couple of ways to do what I’m trying to do it looks like. Assume for the code below that the only differences are the ones listed, and the rest of the code is kind of irrelevant to the question because the rest of it is identical. I don’t want to get hung up on the specifics of the rest of the code, only the shared lines.

I can do this:

``if "[the singular of the object kind of y]" matches the regular expression "(?i)^[x]\$" or "[the singular of the parent of the object kind of y]" matches the regular expression "(?i)^[x]":``

or this

``if the object kind of y is x or the parent of the object kind of y is x:``

The first option ends up with phrases like this:

``````To do whatever with (x - a text):
foo;

foo:
do whatever with "object-code-name";``````

The second one ends up with phrases like this:

``````To do whatever with (x - an object kind):
foo;

foo:
do whatever with the object kind of a random object-code-name;``````

Which is a better what to do it in terms of performance, the normal way you might expect this kind of code to be written, etc.?

The second will be much faster and more efficient. Regular expressions are slow and in this case unnecessary, and an object kind variable is much smaller than a text variable.

Thanks. I’ll go with that, but I thought I’d ask because the second one is a little awkward and unwieldy in the phrase that calls the function as in “do whatever with the object kind of a random object-code-name;” or even worse “do whatever with the parent of the object kind of a random object-code-name;”. This isn’t very intuitively understandable, as opposed to "do whatever with “object-code-name”… which is still not 100% intuitive, but it’s substantially clearer.

Nevertheless, I am worried about performance, so if one is better on performance, I pick it. Thanks again!

It shouldn’t be too hard to allow the author to type in the name of a kind for that, using kind variables. I’ll see what I can do.