Questions about objects and kinds in I7

So I’m still pretty new to using Inform, and partway through coding my current project (which has a pretty in-depth clothing system), I realized that I have about ten different kinds of “garments” (shirts, pants, skirts, hats, etc), and that each of those kinds can have multiple specific objects. This system has worked out well for some of the things I want to do (determining whether eg a pair of pants can be put on based on what the player is already wearing, mainly), but I very frequently want to be able to just refer to things more generically in text–like saying “your pants/skirt” based on which the player is wearing, or having the description text for an item say that that item is a dress in an automatically generated way where I don’t have to write out every description for every article of clothing.

The other issue has been having text which refers to specifics of the, for instance, pair of socks the player is currently wearing, when that could be any of a number of pairs of socks and “pair of socks worn by the player” isn’t considered a specific object by inform even though I’ve coded it in such a way that they won’t be able to put on a pair of socks if they’re wearing one (I mean, I get why it does it, but I haven’t been able to find a good alternative here).

Basically, I feel like I have good potential solutions to these problems IF there was an easy way to get to the kind that’s one up in the tree. So if I have a blue dress, and I had some sort of way to access the kind of garment it is (dress) without having to make ten if statements every time (tried to turn this into a “to decide” rule I could call on, but it doesn’t seem to like having a kind of thing and not a specific thing as the value being decided on, nor did it like the table I made with a bunch of kinds of objects as entries).

Also potentially helpful: a way to turn “pair of socks being worn by the player” into something Inform will accept as a specific object, OR to take the first entry out of a list and put it into a variable (a significantly jankier solution, but one I can’t foresee having problems in this specific implementation).

Would I be better off switching from having the garment > kind of garment > specific garment tree to just having the kind of garment be a property so I could access it the way I want to? Is there some better way I haven’t thought of?

I don’t think there’s any way of accessing the kind of an object directly. You could do something like this:

A garment has a text called kind_name.
The kind_name of a dress is usually "dress".

Rule for printing the name of a worn garment while taking inventory: say "Your [kind_name]".

To get at the pair of socks currently being worn:

Let current_socks be a random pair of socks worn by the player.

(If the player is not wearing socks, this will evaluate to nothing.)

The extension Object Kinds by Brady Garvin lets you work out what the lowest-level kind of an object is. jrb is correct that there isn’t anyway to do this without diving down to I6, as that extension does; the best available solution in I7 is probably something like jrb’s, where you assign some texts to everything of the same kind and then check the text whenever you need to check the object kind.

jrb’s solutions are pretty much the workarounds I was angling for but couldn’t quite get to work properly. Thank you so much for the random x worn by player answer, I knew there had to be a way to do that and I was banging my head against a wall trying to figure it out.

I’ll look into that extension, though, I think it might be more of a blanket fix than the kind_name text.

Thanks to you both!

A garment has a text called kind_name.
The kind_name of a dress is usually "dress".

It will be slightly faster to declare a kind-of-value:

A garment-type is a kind of value. The garment-types are dress-type, shirt-type, [etc]
A garment has a garment-type.
The garment-type of a dress is always dress-type.

I see that this would be good for things like switch statements, but it won’t really help us to print the name of the kind, which I think was one of the things that OP was asking about.

You can write a switch statement which prints the value (without the “-type” suffix). If you’re doing any other logic on type comparison, it’s a net win. (Although maybe not enough of a difference to be worth worrying about, for a small game.)

FYI, there is a uservoice suggestion about this to which you can add your vote: … -of-a-kind

For the specific task you are working on, you may not want to reinvent the wheel.
for … 20Clothing (Google Drive link on site)

As to the my/her/his issue, the latter has solved part of this with an elegant hack in his Erotic Storytelling extension in development. I’ve excerpted the clothing code, but a similar rule is used for body parts.

[code]Chapter 1.1.2f - Understanding

A garment has some text called wearer’s pronoun.
Understand the wearer’s pronoun property as describing a garment.
Does the player mean examining a garment that is worn by player: It is unlikely.

Chapter 1.2.0a - Startup Procedures

When play begins:
Repeat with cloth running through the garments:
Update pronoun for cloth;

To update pronoun for (G - a garment):
If G is worn by a person (called P):
If P is the player:
Now wearer’s pronoun of G is “my”;
Else if P is worn a man:
Now wearer’s pronoun of G is “his”;
Else if P is a woman:
Now wearer’s pronoun of G is “her”;
Now wearer’s pronoun of G is “their”;
Now wearer’s pronoun of G is “their”;