Identifying the kind of something, in a rule

I’d like to do something like that :

Instead of taking something (called S) when the player is carrying something of the same kind of S : say "You already have a [kind of S] !".

I could make a rule for each kind of thing, but I’d like to understand how that works.

Thanks !

That’s something that comes up fairly often, but it’s a bit tough!

For one thing, “Kind of S” is not unique, since a thing can be a kind of something that is itself a kind of thing. Suppose clothing is a kind of thing, hats are a kind of clothing, and gloves are a kind of clothing. If the player has a hat and picks up gloves, should it refuse on the grounds that the player already has clothing? That’s probably not what you want.

There’s an extension Object Kinds by Brady Garvin which would let you get the most specific kind for any object, which would take care of the example above. But you still might not want this behavior; if you’ve defined things that aren’t of any special kind (like “A knife and a fork are in the Kitchen”), then they’ll both show up as kind “thing,” and you probably want the player to be able to pick them up. Though you could take care of this by special-casing so it doesn’t apply to “thing.”

My usual approach to this is to set up a relation among things of the same kind to block this, but then it wouldn’t give you the name of the kind. (That is, you could set a relation that relates every hat to every hat, every shoe to every shoe, and so on, and prevent the player from picking up something that bears that relation to something they’re carrying–but that rule wouldn’t give you a nice way to print “You already have a hat!”… though if you were willing to settle for the printed plural name property you could probably get the message “You don’t need two hats!”) So maybe Object kinds is the way to go.

As a note, the suggestion to make it easier to do things like this in native I7 is officially under review.

Thank you for the quick answer :slight_smile: I’ll give that extension a try. It always can be useful.

My aim is not particularly preventing the player from having two swords (for example). What I’d like to know, above all, is how to make the player take the sword which is lying on the ground - when Inform, by default, makes him " take " the sword he’s already carrying, which is absurd (or, there is something I don’t understand).

That’s odd – “take” normally tends to prefer things you’re not carrying, all other things being equal. For example, the following example takes the sword on the ground:

[code]Test Chamber is a room.

A sword is a kind of thing.

The player carries a sword.

The Test Chamber contains a sword.

Test me with “take sword”.[/code]

Can you post example code that replicates this specific problem?

:blush: :blush: :blush: :blush: Well… it works. I don’t how I managed to have problems with that - probably my own bad-written rules, interfering with this and that … Thank you !

Hey, Emily would like to encourage people to add uservoice votes. That’ll make it more visible. Since it comes up often, it should be more visible!