How do I get an NPC to enter a container? Specifically, I have a cat that can be lured into a pet carrier when a toy is placed inside.
Ah, never mind–“now the cat is in the second noun” works.
Robot Found Kitten in the second noun.
[size=85]I wonder how many people around here today will get this one. [/size]
Now the opposite question: how do I get the cat out again? Inform is not happy with “now the cat is not in the second noun”.
You have to specify exactly where the cat goes. If the pet carrier can be moved around, so you don’t know exactly which room the cat is going to be in when the pet carrier is opened (or whatever it is that triggers this), you can try “Now the cat is in the location of the pet carrier”–location of the pet carrier is the room the pet carrier is in. (I’m assuming there isn’t a special case where, if the carrier is on a table, the cat winds up on the table–my cat would just jump to the floor anyway.)
You probably don’t want “second noun” here; the “second noun” refers to the second thing specified in the action. It worked in your original case because the action was “PUT TOY IN CARRIER” so the first noun was the toy and the second noun was the carrier, but in this case if the action is “OPEN CARRIER” then the carrier will be the noun and the second noun will be nothing. (This probably applies to your original case too–you can just say “now the cat is in the carrier” instead of “now the cat is in the second noun,” since you know that it’s the carrier that you want to put the cat into.)
I said “second noun” because technically it doesn’t have to be the pet carrier; you can lure the cat into any container with the toy. It’s just that the carrier is the only closable container, so it’s the only one the cat can’t escape. I did put in a special case for the carrier being on a table.
Here’s code for the cat’s escape:
Every turn when the cat is in a container (called the cat-holder): if the container is open: now the cat is in the location of the cat-holder; if the cat-holder is on a supporter (called the surface): now the cat is on the surface; say "The cat grows bored and wanders out of [the cat-holder]."
This works fine except that the cat escapes the carrier immediately, before the player has the opportunity to close it:
>put toy in carrier (first taking the catnip toy) You put the catnip toy into the pet carrier. The cat, smelling the toy, crawls into the pet carrier after it. The cat grows bored and wanders out of the pet carrier.
Any advice? How do I delay the cat’s escape by one turn?
Yep, you definitely want “Second noun” then! Carry on.
And if you want to make the cat jump onto the table instead of onto the floor, you can actually use the phrase “holder of the cat-holder” instead of special-casing it. So:
Every turn when the cat is in a container (called the cat-holder):
if the cat-holder is open:
move the cat to the holder of the cat-holder;
say "The cat grows bored and wanders out of [the cat-holder]."
Oh, and you have to say “if the cat-holder is open” rather than “if the container is open”–the last one evaluates to true if any container in the whole game is open. (Inform doesn’t know that “the container” means the one you were just talking about, so it treats it as “a container.”
As for your problem… hmm, there are a few ways to do it. One would be to set a flag on the turn that you put the toy in the container, so the cat doesn’t exit it that turn. There are probably more automatic ways to do this too. Although what I might do is put the code that moves the cat into the container into an every turn rule, and have that rule run after the rule that has the cat leave the container… though, on a test, that has the opposite problem, because the cat jumps out of the cat-carrier and immediately back into it. Oh well.
You can also take care of this with the action mechanisms–instead of moving the cat yourself, have the cat try entering the container and exiting. Then the rules for those actions will take care of things like checking that the cat can’t exit the cat-carrier when it’s closed; and also things like the cat can’t enter the cat-carrier from another room, and even that it can’t enter the cat-carrier while you’re holding it! An implementation:
[code]Exited this turn is initially false.
Every turn when the cat is in a container (called the cat-holder) (this is the cat gets bored rule):
try the cat exiting;
now exited this turn is true.
Every turn when the toy is in a container (called the trap) and exited this turn is false (this is the cat chases toy rule):
try the cat entering the trap.
The cat gets bored rule is listed before the cat chases toy rule in the every turn rulebook.
Last every turn: now exited this turn is false.
Kitchen is a room. The cat-carrier is an open openable enterable container in the Kitchen.
Check entering the cat-carrier: say “It’s too small to hold you.” instead.
The cat is an animal in the kitchen.
The player carries a toy.
After the cat exiting: say “The cat grows bored and jumps out of [the container exited from].”
After the cat entering a container (called the trap) when the toy is in the trap:
say “Smelling the toy, the cat jumps into [the trap].”
Dining room is south of kitchen.
test me with “put toy in cat-carrier/z/z/close cat-carrier/open cat-carrier/take cat-carrier/s/drop cat-carrier/take cat-carrier/actions/rules/n/actions off/rules off/close cat-carrier/drop cat-carrier/open cat-carrier”.
Every turn when the cat was in a container and the cat is in an open container (called the cat-holder): if the cat-holder is on a supporter (called the surface): now the cat is on the surface; else: now the cat is in the location of cat-holder; say "The cat grows bored and wanders out of [the cat-holder]."
It’s slightly convoluted because you can’t use “(called the cat-holder)” with “was” directly. As I7 puts it:
There’s also the potential for a subtle problem if the container that the cat was in is a different one from the container that the cat is currently in, since it might not have been in the new container for a full turn, but this seems not to be possible in your game as you described it.