Intercept parser errors

You could do something like

Understand "take all/everything from [coat]" as empty-removing when the first thing held by the pocket is nothing.

Empty-removing is an action applying to one thing.

Carry out empty-removing:
	say "The coat pocket is empty."

Of course you would probably want to add the grammar lines for “get all/everything from” and “remove all/everything from” as well,

EDIT: There is a different rabbit hole regarding TAKE STICK AND VASE FROM COAT and TAKE ALL BUT STICK FROM COAT when the pocket is empty, but this is as far down as I’m prepared to go.

Here’s some additional strange behavior with all and pockets. This is using CoatTest from above, and is the same with or without the pocket-removing code:

>wear coat
(first taking the coat)
You put on the coat.

>x pocket
In the pocket are a pen and a handkerchief.

>take all from pocket
There are none at all available!

>take off coat
You take off the coat.

>take all from pocket
There are none at all available!

>drop coat
Dropped.

>take all from pocket
pen: Taken.
handkerchief: Taken.

Notably, this does not occur for inserting into, so it’s probably related to the special-case code in the parser for taking and removing. Just to make things stranger, take all from pocket does work when the pocket contains 1 thing.

Anyway, here is an alternative approach that avoids introducing new actions by introducing more ambiguity:

Understand "coat" as the pocket.
Does the player mean removing from the coat: it is very unlikely.
Does the player mean inserting into the coat: it is very unlikely.

Does the player mean removing from the pocket: it is likely.
Does the player mean inserting into the pocket: it is likely.
Does the player mean doing something to the pocket: it is unlikely.

Rule for clarifying the parser's choice of the coat: rule succeeds.

This seems to work pretty well. The actual set of does the player mean rules may need to be tuned further.

The rule for clarifying the parser’s choice is there to avoid printing (the coat) every time you do something involving the coat. That may also need to be narrowed.

The TAKE ALL FROM POCKET issue while wearing the coat is due to a bug in the “exclude indirect possessions from take all rule” from Standard Rules.

This has the definition:

Rule for deciding whether all includes things enclosed by the person reaching
while taking or taking off or removing (this is the exclude indirect
possessions from take all rule): it does not.

As far as I can tell, the or removing part does not work as intended and should not be there at all. It breaks TAKE ALL FROM carried containers.

In Counterfeit Monkey, I fixed this by replacing the rule entirely:

Rule for deciding whether all includes things enclosed by the player while taking (this is the new exclude indirect possessions from take all rule):
	it does not.

The new exclude indirect possessions from take all rule is listed instead of the exclude indirect possessions from take all rule in the for deciding whether all includes rulebook.

This seems to work in the current case as well.

Your fix does solve that particular problem. I am puzzled why taking off is there, since it does not work with all in the first place.

I notice your changed the person reaching to the player, which makes me wonder if this affects the player asking an NPC to do something. But some experiments show that this is somewhat broken out of the box: if you make the boy persuadable, and ask him to take all, he will attempt to take himself.

By adding an actor strategically, I can make the code using pocket-removing work when asking an NPC to take all from the coat. To take the understand-“coat”-as-pocket approach, I can make it work if I add the rules below, but I wonder if there is a better approach.

Does the player mean asking someone to try removing from the coat: it is very unlikely.
Does the player mean asking someone to try inserting into the coat: it is very unlikely.

I have a similar problem so this has been illuminating - thank you.

Where can I read the Standard Rules?

That depends on why you’re looking for them. :slightly_smiling_face:

The actual real Standard Rules themselves can be read by going to File → Open Extension → Graham Nelson → Standard Rules. But they’re not really documented and can be hard to read through unless you already know what you’re looking for. They also only tell half the story, as a great deal of things are implemented in the I6 code instead, which is less easily readable (though you can still find it if you go looking).

You might want to have a read through of the annotated rules; this is quite old (I’m not sure if there’s a newer version around somewhere) and many things have changed since then, but a lot of it does still apply, so this may help, especially if you compare the rules here with the real Standard Rules.

Having said all this, for most purposes a combination of looking in the Documentation and looking in the Index (especially the latter) gets you a long long way, without needing to look too closely at the Standard Rules themselves.

For example, clicking through Index → Actions → Taking shows you all of the Check rules controlling that action. While this doesn’t tell you the precise conditions it checks, usually this is fairly apparent from the names of the rules, and if not, once you know the name of the rule you can more easily locate it within the Standard Rules themselves. Better still, the Index automatically updates with any extensions you’ve included as well as rules from your own story.

To find that particular rule mentioned above, though, you need to look at the Rules tab instead, under the deciding whether all includes activity. Using the RULES debugging verb is another way to help locate which rules are affecting things in play.

I notice your changed the person reaching to the player

When replacing code in the Standard Rules, it is generally a good idea to stay as close to the original as possible, because you can never be sure what you’ll break otherwise. In this particular case, I disregarded that in order to make the new code clearer. I don’t recommend this. Fortunately, it seems to have caused no unwanted side effects, probably because the things you can order NPCs to do in Counterfeit Monkey are very limited.

My situation is that I have (using the equivalent things being discussed here) a coat with four pockets. I wondered whether I could amend a Standard Rule so that for “get all from coat” I could add the contents of first pocket, second pocket etc to the (empty) list of items found in the coat before the action starts. (My version of the coat can’t be worn so that aspect of it doesn’t apply.)

I’ll look through your advice when at the computer and see whether I get anywhere! Thanks.

(Edited to change “work” to “worn”.)

You might want to take a look at multiple action processing rules, §6.15 in the documentation, before messing with the standard rules.

I will take that as a warning! I didn’t find anything useful in that part of the documentation, but I’ll look through it all again together with the advice here tonight.

Thanks again.

Thanks for all your ideas. Instead of a coat with a pocket, I have a hamper with compartments. Here is what I have currently. I hope this helps Andy and his coat pockets, and would be grateful to hear if you see any potential pitfalls.

So that the player can use “get all from hamper” to get all from its compartments:

Understand "take [things] from [hamper]" as multiple-removing.
Understand "get [things] from [hamper]" as multiple-removing.
Understand "remove [things] from [hamper]" as multiple-removing.
Multiple-removing is an action applying to two things.
Carry out multiple-removing:
	try removing the noun from the second noun;
	say "[run paragraph on]".

(Run paragraph on just makes it look neater until I find a better way.)

So that “all” only tries to take things in the hamper out of it:

Rule for deciding whether all includes things enclosed by a compartment when multiple-removing: it does.
Rule for deciding whether all includes things not enclosed by a compartment when multiple-removing: it does not.

So that the player can take things from a carried container:

Rule for deciding whether all includes things enclosed by the person reaching while taking or taking off (this is the new exclude indirect
	possessions from take all rule): it does not.
The new exclude indirect possessions from take all rule is listed instead of the exclude indirect possessions from take all rule in the for deciding whether all includes rulebook.

To replace the “[There] [adapt the verb are from the third person plural] none at all available!” message with something better:

Rule for printing a parser error when the latest parser error is the nothing to do error and the player's command includes "from hamper":
	if the hamper is empty:
		say "The hamper is empty." instead.

(Edited to add “or taking off” after “taking” in the rule.)

After taking the time to read all these excellent contributions to this discussion, I have come up with my own solution to the “little” scenario I created to test my coat / pocket idea. I actually wanted to have a coat be more of a kind - for example, a jacket is a coat, a raincoat is a coat. Every coat would have a pocket. This put some of the suggestions which relied on an actual coat a little difficult to apply but I think I have a useable model which for the most part does what I want. I have not tested all thoroughly though, so I may have missed some caveats :slight_smile: I have also made the boy persuadable and getting the boy to take all from jacket (or any coat) seems to work. Once again thanks for all the comments and help here.


“CoatTest” by AndyG

Instead of an actor inserting into a coat (called the target): try the actor inserting the noun into the pocket of the target instead.

Understand “take [something] from [a coat]” as pocket-removing.
Understand “take [things] from [a coat]” as multi-pocket-removing.
Understand “remove [something] from [a coat]” as pocket-removing.
Understand “remove [things] from [a coat]” as multi-pocket-removing.
Understand “get [something] from [a coat]” as pocket-removing.
Understand “get [things] from [a coat]” as multi-pocket-removing.

pocket-removing is an action applying to two things.

multi-pocket-removing is an action applying to two things.
first check an actor multi-pocket-removing:
try the actor removing the noun from the pocket of the second noun.

carry out an actor pocket-removing:
try the actor removing the noun from the pocket of the second noun.

A multiple action processing rule when the action name part of the current action is the multi-pocket-removing action (this is the strip-pocket rule):
let L be the multiple object list;
Let R be a list of objects;
repeat with O running through L:
if O is not in the pocket of the second noun:
add O to R;
remove R from L;
alter the multiple object list to L;
if L is empty:
say “[The second noun] is empty.”

To decide which object is the pocket of (item - coat):
Repeat with P running through things enclosed by the item:
if P is a pocket:
decide on P;

Rule for deciding whether all includes things enclosed by a person while taking (this is the new exclude indirect possessions from take all rule):
it does not.

The new exclude indirect possessions from take all rule is listed instead of the exclude indirect possessions from take all rule in the for deciding whether all includes rulebook.

Rule for deciding whether all includes things in a container while taking: it does not.

Rule for deciding whether all includes things on a supporter while taking: it does not.

A boy is in the cloak room. The boy is a male person.
A persuasion rule for asking the boy to try doing something: persuasion succeeds.

A nose is a kind of thing.
A nose is part of every person.

The cloak room is a room.

A vase is a container in the cloak room. In the vase is a flower and a stick.

A coat is a kind of thing. A coat is wearable. Understand “coat” as coat.

A pocket is a kind of container. A pocket is part of every coat. Understand “pocket” as pocket.

A raincoat is a coat. It is in the cloak room. Inside the raincoat’s pocket is a pen and a handkerchief.

A leather jacket is a coat. It is in the cloak room. Inside the leather jacket’s pocket is a penny and some fluff. The fluff is singular-named. The indefinite article of the fluff is “some”

Reminder to use the </> button when pasting code, otherwise it loses the indentation and gets jumbled in other ways.

You shouldn’t need to define the pocket-removing and multi-pocket-removing actions separately, though. Just define pocket-removing with the content of multi-pocket-removing and it will work for both.

You don’t need separate Understanding lines for single and multiple items, either.

Understand "take [things] from [coat]" as pocket-removing.

That works for one or more things.

Also, you might as well have pocket-removing redirect to taking without going through removing from.

Incidentally, do the multiple action processing rules show up anywhere in the index? I haven’t been able to find them. (Or the accessibility rules, for that matter.)

That’s what I said. :wink:

The accessibility rules is an undocumented rulebook – you’re supposed to put rules in the reaching inside rules, reaching outside rules, or visibility rules instead (which do appear in the Rules tab). Although there are a few things you can do more easily in that parent rulebook instead.

Multiple action processing is documented but it doesn’t seem to be listed anywhere in the Index. Not sure if that’s an omission or if it’s intentionally hidden for some reason.

I’ve amended my code accordingly.

Thanks everybody for your help.

Andy - Good luck!

1 Like

I believe you said that pocket-removing and multiple-pocket-removing could be the same action. I was referring to some of the code posted earlier, which looked like this:

Understand "take [something] from [coat]" as pocket-removing.
Understand "take [things] from [coat]" as pocket-removing.

Here, the first line is unnecessary.

Does example 216 (Waterworld) count? The example itself doesn’t really use the accessibility rules correctly, but it definitely uses one.

For that matter, the standard rules include exactly one accessibility rule. Why even use a rulebook unless the intent is to allow more of them?

You can replace the entire accessibility system by replacing that rule. But the topic is too complicated for the manual.

I have also amended my code and all seems to be working. Just a slightly off topic question (brought on by the answers in this thread) - I made the boy persuadable in my example and added some persuasion rules. One of the rules allows for the boy to give the player an item. If the boy does not have the item he attempts to take it (silently) before “giving”. Is there a way to stop a NPC from attempting the silent take and only “give” if they already have the item? Many thanks - AG

Just condition that particular persuasion rule on when the boy carries the widget.