Making exception for a not animated object (parser error rule)

I’d like to edit the “you can only do that to something animate” error so that it is different for a specific not animated object. I tried something like:

Rule for printing a parser error when the latest parser error is the can only do that to something animate error:
	if the noun is statue:
		say "You may think this is an animate thing, but it isn't.";
    otherwise:
        say "You can only do that to something animate.".

But it seems that no matter which thing is typed by the player (such as “ask statue about”), the parser will always print the standard “You can only do that to something animate.”.

When you encounter this particular parse error, parsing has failed, so there is no noun. So that strategy can’t work.

(It’s a weird case because the parser has found a specific object, and determined that it’s not animate. So it’s a reasonable thing to try to do. But the specific object has not yet been stored in the noun variable.)

Look at the “Inanimate Listeners” extension for an easy way to make a statue talkable.

5 Likes

Here’s a small bit of Inform 6 hackery to make this possible (written for Inform 7 10.1).

To decide what object is the creature misunderstood: (- creature_misunderstood -).
to reset creature misunderstood: (- creature_misunderstood = 0; -).

Include (-
Global creature_misunderstood;
[ CreatureTest obj;
    creature_misunderstood = obj;
    if (obj has animate) rtrue;
    if (obj hasnt talkable) rfalse;
    if (action_to_be == ##Ask or ##Answer or ##Tell or ##AskFor) rtrue;
    rfalse;
];
-) replacing "CreatureTest".

For printing a parser error when the latest parser error is the can only do that to something animate error and the creature misunderstood is the statue:
say "You may think this is an animate thing, but it isn't.";

This is the reset misunderstood creatures rule: reset creature misunderstood.

The reset misunderstood creatures rule is listed in the after printing a parser error rules.
The reset misunderstood creatures rule is listed in the before reading a command rules.
3 Likes

I feel that it’s worth mentioning that you get the ‘something animate’ line because the only grammar line that otherwise would match has “[someone]” instead of “[something]” in it.

This means that if you want to define a new verb or new grammar line with '[something]" in it, you can then write your own error messages to your heart’s content:

Understand "kiss [something]" as kissing.

Instead of kissing something:
	if the thing is not a person:
		say "You kiss [the noun], feeling foolish.";
	otherwise:
		continue the action;

You’ll then have to worry about scenery, etc. just like any new verb.

2 Likes

Any reason to use a special variable instead of clobbering noun? It’s not like it’s needed for anything else at that point.

I wanted to make sure the value got clobbered after use so it wouldn’t haunt us later. If I’d used noun I would have needed to think more about ensuring I wasn’t clobbering noun when I shouldn’t be, and it plain didn’t seem worth the extra thought. (I am also pretty much never considering how to skimp to squeeze things into the Z-machine; my cavalier profligacy in creating globals reflects this disregard.)

2 Likes

I’m not experienced with this grammar, but that looks amazing! How could I make it work for Inform 7 9.2 (I’m using build 6L38 for compatibility with some extensions)?