Trouble with Tables (Lookup not working)

Hiya. What’s wrong with this syntax? When I request actions for something, say, an apple, it can’t find it in the list. Thanks in advance!

[code]
Carry out requesting actions for something (called item):
if item is a thing listed in the Table of Possible Actions:
say “FOO”;
otherwise:
say “BAR”.

Table of Possible Actions
Thing Actions
apple {“EAT”, “POLISH”}
banana {“EAT”, “PEEL”}[/code]

I’d recommend not naming a column “thing” just to avoid problems down the road. But the more common syntax for this sort of lookup would be

if there is a [column name] of [entry] in [table]...

Thanks, but that doesn’t work for me either.

I think you may be running into a disambiguation problem with “thing” then. Change that to something else.

Apple isn’t a kind of thing rather than an individual thing, is it? You can’t actually put kinds in table entries. I think there used to be a bug where the compiler would accept this and treat it as effectively a blank entry, leading to malfunctions. I also think this may have been fixed (so that if “apple” is a kind a table with “apple” in it will, properly, fail to compile)–but I don’t have Inform fired up to check.

It IS a kind of thing. Hm. I’m not sure what else to do. For reasons, I can’t make requesting actions work with a topic, and I’ve tried casting my item to a text (“[item]” which works elsewhere for me).

A quick hack is something like this (totally untested):

[code]A thing has some text called action-lookup text.

The action-lookup text of an apple is usually “apple”.
The action-lookup text of a banana is usually “banana”.

Carry out requesting actions for something (called item):
if the action-lookup text of item is a string listed in the Table of Possible Actions:
say “FOO”;
otherwise:
say “BAR”.

Table of Possible Actions
String Actions
“apple” {“EAT”, “POLISH”}
“banana” {“EAT”, “PEEL”}[/code]

(Note that “string” is just a name I picked for the table column–you could use anything there.)

…actually I’m not positive that these text comparisons will work as intended, but you could try it.

There are probably less kludgey ways to accomplish this.

This works. Thank you. Is there some way to generate action-lookup texts without listing each one? I tried something like

The action-lookup text of something (called item) is usually "[item]"

but of course this doesn’t work.

You could try something like this:

When play begins: repeat with item running through things: now the action-lookup text of item is the substituted form of "[item]".

You might want to make sure this works though. If you have an apple with a specific name, like “the golden apple,” this will set the action-lookup text to “golden apple” which won’t work. One hack I sometimes use is to use the printed plural name of the thing

now the action-lookup text of item is the printed plural name of item.

By the way, there’s an extension Object Kinds by Brady Garvin which might be the way to do this without so many hacks.

This might all be easier if you used rules instead of a table.

Carry out requesting actions for an apple:
    do something with {"EAT", "POLISH"};

Carry out requesting actions for a banana:
    do something with {"EAT", "PEEL"};

(Apple, banana could be kinds or specific things.)

I second the recommendation for Object Kinds. If you want to work with kinds it’s easier to use their indices directly rather than fiddling with text substitutions.

This works fine for one or two items, but not so well for dozens.

I can’t figure out how to apply Object Kinds to this problem?

I do it for dozens. Hadean Lands uses rulebooks for alchemical responses, and those have lots and lots of cases. Each case is a rule.

Include Object Kinds by Brady Garvin.

Table of Properties
kind index    other data
the object kind for bananas    24
the object kind for apples    36

I don’t know if Inform will accept this, since “the object kind for” is an I7 phrase, but you can also hard-code the numbers if need be.
It still looks somewhat ugly, but it should be better than fiddling with text all the time.

Did you make sure to initialize the apple and banana as objects? (It doesn’t show in your code, so I wanted to check.)

This works just fine for me:

[code]The Lab is a room.

An apple is in the Lab.
A banana is in the Lab.
An orange is in the Lab.

Table of Possible Actions
thing action-list
apple {“EAT”, “POLISH”}
banana {“EAT”, “PEEL”}

Giving syntax is an action applying to one thing.
Understand “syntax [something]” as giving syntax.

Carry out giving syntax:
if the noun is a thing listed in the Table of Possible Actions:
say “FOO”;
otherwise:
say “BAR”.[/code]

I think we’re still in the case where apple and banana are kinds of things.

Whoosh straight past me. That makes more sense.