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]
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.
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.
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.