Taking when container is closed

I can’t work out why this code won’t work.

[code]
The description of dead scientist is “It is not evident how he died, though his lab coat is stained with a lot blood, In his hand is a [bold type]bloody note[roman type].”

Scientist’s Hand is a transparent closed openable container. Scientist’s Hand is part of Dead Scientist.

Bloody note is a thing in Scientist’s Hand. Understand “piece of paper” as bloody note. The description of the bloody note is “A hastily scrawled note has been written on a torn piece of white paper, stained with drops of red blood. You can’t read what it says from here.”

Instead of taking the bloody note when the scientist’s hand is closed, say “I try to take the piece of paper, but his fingers are clasped tightly around it. I find I cannot remove the paper from the dead scientist’s hand without tearing it.”.[/code]

When I test it:

[code]>examine dead scientist
It is not evident how he died, though his lab coat is stained with a lot blood, In his hand is a bloody note.

examine bloody note
A hastily scrawled note has been written on a torn piece of white paper, stained with drops of red blood. You can’t read what it says from here.

take bloody note
Scientist’s Hand isn’t open.

[/code]

How come my Instead of taking the bloody note when the scientist’s hand is closed, is ignored?

Taking the note fails the “basic accessibility” rule, which runs before any Instead rules you might have going on. You can see this by turning on “rules” and “actions” listing; you will get this output:

which as you can see doesn’t cite any check rules or anything like that. In order to let you interact with something that’s inside a closed container, you need rules for reaching inside the container, as discussed here.

I think a rule that will work in your case is:

A rule for reaching inside the scientist's hand: if scientist's hand is closed: say "I try to take the piece of paper, but his fingers are clasped tightly around it. I find I cannot remove the paper from the dead scientist's hand without tearing it."; deny access; otherwise: allow access.

In fact I don’t think you need the “otherwise,” since open containers are accessible by default.

(Further testing reveals that if you want to have the scientist’s hand open when you give him pie, you will have to write some special code somewhere. Presumably you have a different solution in mind. In my defense, I already had pie lying around in the code I was testing this in.)

Also, you have “a lot blood” where you want “a lot of blood,” and your narration seems to switch from second to first person – is that intentional?

In fact I don’t think you need the “otherwise,” since open containers are accessible by default.

(Further testing reveals that if you want to have the scientist’s hand open when you give him pie, you will have to write some special code somewhere. Presumably you have a different solution in mind. In my defense, I already had pie lying around in the code I was testing this in.)

Also, you have “a lot blood” where you want “a lot of blood,” and your narration seems to switch from second to first person – is that intentional?
[/quote]
Ah thanks, that worked perfectly. It wasn’t my intention to switch perspectives, thanks for pointing it out.

In a case like this, where you can see something inside a container but can’t reach it, you could alternatively use a before rule.
Before rules run before the basic accessibility rule, so this will also do the trick: Before taking the bloody note when the scientist's hand is closed, instead say "I try to take the piece of paper, but his fingers are clasped tightly around it. I find I cannot remove the paper from the dead scientist's hand without tearing it."