Testing if an object is a certain type - using tables

I wanted to have a table of kinds of things that I could use to test if the player is carrying a certain kind of object (rather than a specific object), but I can’t figure out how to make it work. Here’s a very simple example:

"Kinds"

Equipment room is a room;

ball is a kind of thing.

hat is a kind of thing. a hat is always wearable.

bat is a kind of thing.

table of stuff
type	message
ball	"It's a ball of some kind. You could probably throw it."
hat	"It's a hat of some kind. You could probably wear it."
bat	"It's some kind of bat. You could use it to hit things."

baseball is a ball in the equipment room.
basketball is a ball in the equipment room.
cap is a hat in the equipment room.
cricket bat is a bat in the equipment room.
tennis racket is a bat in the equipment room.

Instead of examining something:
	if the noun is a type listed in the table of stuff:
		say "[message entry]";
	otherwise:
		continue the action;

It should, if I was to say, “x baseball”, see that the baseball is a kind of ball and therefore display the associated message. Needless to say, it doesn’t. What’s the right syntax here? How do I say if the noun is of a particular kind? (with the kind taken from a table)

Tables aren’t necessary.

"Kinds" by I4L

A ball is a kind of thing. The description of a ball is usually "It's a ball of some kind. You could probably throw it."

A hat is a kind of thing. A hat is usually wearable. The description of a hat is "It's a hat of some kind. You could probably wear it."

Equipment Room is a room. "There is a lot of sports gear lying around."

Instead of taking a ball when player carries a ball:
	say "Hey, buddy! You can't play with more than one ball!"

Baseball is a ball in the Equipment Room.
Basketball is a ball in the Equipment Room.
Helmet is a hat in the Equipment Room.

Test me with "x baseball/x basketball/x helmet/get baseball/get basketball/drop baseball/get basketball/get baseball/drop all/get all/wear helmet"

Updated the example to show rudimentary testing of carrying kinds, which I think is what the initial question was?

I’m also pretty sure you’re missing something in that table look up/say. But as I don’t use tables, I couldn’t tell you what without going to look it up.

Thanks but, I know tables are strictly necessary, but neither is my very simple example the be all and end all of the real problem I’m trying to tackle. What I have to do is test whether a player has done something with a number of different types (kinds) of object. I’m using the table so I can blank at rows as they are done. When the table is empty, I know all the preconditions have been met.

As an example, change my above example with this:

Even this doesn’t quite capture everything I’m trying to do, because I want to also enforce the order. So the second row doesn’t get blanked out until the first row has been blanked out.

I know I could tackle this several different ways, but using a bunch of properties to do it seems like a massive pain in the ass versus keeping track of things in a table.

I haven’t… mentioned… properties…?

I kinda get what you’re trying to do. But I don’t think you can define “kinds” inside of a table, so maybe there’s some confusion there. Your example could work okay, I suppose, but that table won’t have anything to do with “kinds”.

I’ll fiddle with it. Far as I’m concerned, there’s always a better way than tables. If someone with more table-love doesn’t come along before me and knock it out of the park, I’ll let you know what I come up with.

The description of a ball is a property of the ball. But anyway, you can actually define kinds of things using the a table (it’s in the manual on the page about defining things in a table), but that’s not what I’m doing either. What I have is a column of type “kind”, which inform doesn’t seem to have a problem with (although I can’t specify in brackets that it’s “kind” for some strange reason). The problem seems to be with the attempt to compare the noun with a kind in the table.

You can do this:

if the noun is a ball

but for some reason this doesn’t seem to work:

if the noun is a type listed in the table of stuff.

Even though the type should resolve to a kind (for example, ball).

And I’ll give you that the tables in inform are often really awkward to use (inform is really fussy about the exact way you reference a table). But they are useful once in a while.

In the documentation example that you’re referring to, the “kind” was defined outside of the table. The description and some properties were defined inside of it.

Anyway, moot point. I can’t find anything in the documentation anywhere that tells you how to compare something with a specific item entry from the table. Several three star examples about how to look up information on the table, but that’s not what I’m looking for. I have the row that I want. I have the value I want to compare it to. The words “equal to” and “corresponds to” cause Inform to choke…

I hate tables.

wjousts is right about defining kinds with tables – I don’t think there are any examples in the documentation, but it’s mentioned briefly at the end of section 15.16 which refers you to the source for “Reliques of Tolti-Aph.” Here’s a shorter example.

Buuut that won’t help us here, because that example isn’t about retrieving the kind from the table. And here the problem isn’t really about retrieving kinds from tables, it’s about what to do when you’ve retrieved the kind. There may be a syntax that allows you to test whether an object is of a certain kind, once you’ve retrieved the kind from a table, but I don’t know it. It seems like the sort of thing that you ought to be able to do with kind variables, but those really make my head hurt. This thread might have some ideas, but they seem to involve I6 or not work or both.

However, gravel’s comment in there points the way. Instead of trying to get a kind out of the table and see whether a thing belongs to it, give everything of a kind a throwaway property and store that in the table. Thus:

[code]“Kinds”

Equipment room is a room;

ball is a kind of thing.

hat is a kind of thing. a hat is always wearable.

bat is a kind of thing.

A thing has some text called typetext. The typetext of a ball is “ball”. The typetext of a bat is “bat”. The typetext of a hat is “hat”.

table of stuff
typetext message
“ball” “It’s a ball of some kind. You could probably throw it.”
“hat” “It’s a hat of some kind. You could probably wear it.”
“bat” “It’s some kind of bat. You could use it to hit things.”

The baseball is a ball in the equipment room.
The basketball is a ball in the equipment room.
The cap is a hat in the equipment room.
The cricket bat is a bat in the equipment room.
The tennis racket is a bat in the equipment room.

Instead of examining something:
if the typetext of the noun is a typetext listed in the table of stuff:
say “[message entry]”;
blank out the whole row;
otherwise:
continue the action.

every turn:
if the number of filled rows in the table of stuff is zero:
say “You’ve examined one of everything!”;
otherwise:
say “There are still [number of filled rows in the table of stuff] types of things to examine.”[/code]

Couple of notes:
You need to say “filled rows” to get the number of rows you haven’t blanked out – “the number of rows in the table of stuff” will always be 3.
I added articles to the names of your individual things in order to make the output more elegant.
The table may have copypasted funny; watch the tabs.

Thanks matt w. It’s kind of annoying that I can’t just test the kind, but your solution seems to be probably the easiest way to handle it. I’ll give it a try.

And thanks I4L. Hopefully one day you’ll find a space in your heart for inform tables! Maybe after another couple more versions of Inform when they (hopefully) become easier to work with.

As long as they continue to give me alternatives, I’m not going to hold my breath. :smiley:

Glad you got this worked out. Good luck on your project.