Taking item from animal?

Hello!

This is my first post; I made my account because I’m a bit stumped. I’m making a story in Inform 7 for a class project, and I’ve managed to figure out all of my snags except one.

I am using a sort of puzzle game where the player collects a series of keys. The first key is found on the collar of a dog. Every time I try to take the key, the story says that “That seems to belong to the dog.” I managed to figure something out with a web search, but it only worked if the player types “Dog, give me the key.” I thought that that was a bit awkward, so I kept trying, and now I can’t get the key at all. Any tips? My source looks like this:

A dog is here. The dog is a male animal. The dog is fixed in place. The dog carries the bronze key.

After taking the bronze key:
say “The Corgi licks your fingers as you pull the key from his collar.’”;
Now the player is carrying the bronze key.

Any help is appreciated.

An ‘after’ rule only fires if the action succeeds, which it hasn’t. So a built-in rule is stopping the action from succeeding. Let’s find out which one it is.

Before you try taking the key from the dog in-game, use the testing command RULES. This will notify you for every rule that fires: quite a lot, for the taking action. But the last one that you see before the normal game response is the ‘can’t take people’s possessions rule’. That’s part of the Standard Rules, because normally you shouldn’t be able to run around stealing people’s clothes and so on. (Inform treats animals as a special kind of person. This is sometimes helpful and sometimes not; at any rate, don’t assume that ‘animal’ is always the best kind to use for animals.)

Open the Standard Rules. (File/Open Extension/Graham Nelson/Standard Rules.) Use Find to look up the can’t take people’s possessions rule. Well, that’s a bit complicated. You probably want to keep that rule, except that we don’t want it to apply in this specific situation. We could just delist the rule, like this:

The can't take people's possessions rule is not listed in any rulebook.

But then we’d find ourselves in the world of consequence-free depantsings. So instead, you replace it with a rule that almost always points to the old rule, except for when the key’s involved:

[code]
This is the alternate can’t take people’s possessions rule:
if the noun is not the bronze key, abide by the can’t take people’s possessions rule;

The alternate can’t take people’s possessions rule is listed instead of the can’t take people’s possessions rule in the check taking rules.[/code]

Animals are considered persons by Inform, so the “Can’t take people’s possessions” rule (one of the Standard Rules of Inform) is kicking in and preventing you from taking the key from the dog.

One way around this would be to replace that rule as maga does, but in your case I think it might be easier to change your “After taking…” rule to an “Instead of taking…” rule. If you look up the “can’t take people’s possessions” rule, you will find that it is a “check” rule; “instead” rules run before “check” rules, so the instead rule would kick in first (and since it’s an “instead” rule, it prevents the other rules from applying).

A couple of other points: You should really make it “Instead of taking the key when the dog holds the key: [etc.]” Otherwise, you’ll get the message about the dog even if you take the key, drop it, and pick it up off the floor.

If you were going to get the “After” rule working, you wouldn’t need the line “Now the player is carrying the bronze key”; the normal behavior of the taking action transfers the key to the player (in a “carry out taking” rule, I think). Also, I’m surprised that “now the player is carrying the bronze key” compiles; I’d have thought it had to be “Now the player carries the bronze key.” Learn something new every day, I guess.

You might not have to make the dog fixed in place, because there’s a “can’t take other people” rule which would prevent you from taking the dog.

Last, I don’t have Inform open and haven’t been able to check any of this for myself, so it might be wrong!