I’d like to be able to write fairly complex rules to print descriptions of things, and have the parser understand the descriptions that are printed as referring to the things. As a simple example, where the player is looking at colored blocks through glasses that change color:
[more under the spoiler tag]
Now, I got that to happen in Inform 7 by means of an ugly hack: I created a new action for “take [text]” and had it compare the topic understood to the result of the rules for printing the name of every visible item (as indexed text!). (I realize that in this particular instance there are much simpler solutions, like defining another property for the apparent colors of the blocks, but suppose that the rules for printing names of objects were much more complicated.) Code under the spoiler:
[spoiler][code]Use American dialect and the serial comma.
Section - Colors
[This is a bunch of stuff to make the color of a block vary dynamically depending on its real color and the color of the player’s glasses.]
A color is a kind of value. The colors are red, blue, and yellow.
A block is a kind of thing. A block has a color.
The player wears some glasses. The glasses have a color. The description of the glasses is “The glasses are currently colored [color of the glasses]. Push the button to change the color.” Understand “button” as the glasses.
Carry out pushing the glasses:
now the color of the glasses is the color after the color of the glasses.
Report pushing the glasses:
say “The glasses are now colored [color of the glasses].”;
rule succeeds.
For printing the name of a block (called the cube):
if the player does not wear the glasses:
say “a [color of the cube] block”;
otherwise:
if the color of the glasses is red:
if the color of the cube is:
– red: say “a red block”;
– blue: say “a purple block”;
– yellow: say “an orange block”;
otherwise if the color of the glasses is blue:
if the color of the cube is:
– red: say “a purple block”;
– blue: say “a blue block”;
– yellow: say “a green block”;
otherwise: [the color of the glasses is yellow]
if the color of the cube is:
– red: say “an orange block”;
– blue: say “a green block”;
– yellow: say “a yellow block”.
Section - Taking and Examining By Name
[This is where the dynamic parsing happens, such as it is.]
Examining by name is an action applying to one topic. Understand “examine [text]” as examining by name.
Carry out examining by name:
repeat with the item running through visible things:
if “[the item]” matches the text the topic understood:
try examining the item; [really I should be collecting this into a match list, but you get the point]
rule succeeds;
say “You can’t see any such thing.”
Taking by name is an action applying to one topic. Understand “take [text]” as taking by name.
Carry out taking by name:
repeat with the item running through visible things:
if “[the item]” matches the text the topic understood:
try taking the item;
rule succeeds;
say “You can’t see any such thing.”
The Playroom is a room. Block1 is a red block in The Playroom. Block2 is a blue block in The Playroom. Block3 is a yellow block in The Playroom.[/code][/spoiler]
Which is no good. It basically throws out the parser, I’d have to create a new action with a text token for every action I wanted to work (if you try to drop the purple block with the code I’ve written, you’re SOL), and anyway it won’t work for two-noun actions because you can’t have two text tokens in an understand line. (Also articles get messed up here, but I could maybe take care of that along these lines.)
Ideally I’d like to have a way to have these dynamic texts hooked into “[something]” tokens.
So my question is: What if anything can I do to make this happen? Possibilities:
-
A parser hack in I7. I’m pretty sure this can’t happen; poking around Ron Newcomb’s Original Parser extension, it seems as though before the command gets to the parser (as Ron translated into I7) it’s already been resolved into dictionary words, so there’s no way to get something not in the dictionary hooked into a [something] token.
-
A parser hack in I6. From the code Felix kindly posted here, that seems like it might be possible; it looks like the Swedish extension has a way to cast a snippet into indexed text and hook it back into a “something” token. In order to make this work, I’d have to learn I6.
(That code won’t work for me as is, because the text I want to understand isn’t actually the printed name; the blocks retain printed names like “Block1” even if the rules for printing the names output something different.)
-
Something completely different. Would TADS make this easier?
-
Work on one of my less insane ideas instead.
Any thoughts? How deep into I6 would I wind up if I chose route 2?