Unlocking doors

I’m new to Inform 7 and writing IF.
Recently I was experimenting and I tried making a door that is locked, and unlocks not by a key, but when a certain thing (e.g. a Shoe) is in a certain container (e.g. a box).
I tried some things such as:

If the Shoe is in the Box then Unlock the Door. (I created the shoe, box and door beforehand)

But this doesn’t work. It compiles and plays, but it thinks that “in the Box then Unlock the Door” is a thing. What should I do???!!!
Please tell me if I’m missing important punctuation there or something, but that’s almost copied straight out of the manual.

Thanks

This code has a couple of problems. The main issue is that it isn’t tied to an event that Inform can understand. What you want to do is done by Inform through actions, and a sentence beginning with “if” only really makes sense after you’ve tied to an action or other event that Inform understands.

So, what you want to tell Inform is not that the door should unlock if the shoes are in the box, but that the door should unlock after the shoes have been put in the box. Make sense? Inform internally refers to this as inserting something into something else (the player will usually type “put shoe into box”, but you have to use the specific language that Inform understands. The Index is a handy place to see what this language is.) So, something like this:

After inserting the shoe into the box: .... 

The other problem is that, to change the state of the world (e.g. to unlock a door), you need to use the word “now” or “change”:

Now the red door is unlocked.

So, here’s a complete little game that will do something similar to what you want:

The Bedroom is a room. The red door is  east of the Bedroom and west of the Living Room. The red door is a closed door. The red door is locked.

The Kitchen is north of the Living Room.

The box is a container in the Kitchen. The shoe is in the Kitchen. The player is in the Kitchen.

After inserting the shoe into the box for the first time:
	now the red door is unlocked;
	say "You put [the noun] into [the second noun]. A click sounds from [if the location is the bedroom or the location is the living room]the vicinity of the door[otherwise]the south part of the house.";

A note about “after” rules like the one that’s doing all the work here: They don’t allow the normal message of an action to print. In other words, without any such rule, Inform will print “You put the shoe in the box” after the player successfully performs that action. However, because our after rule doesn’t blocks that standard message, we have to present our own text to tell the player that his action succeeded.

You’ll also see that I used [the noun] and [the second noun] to report the success of the inserting it into action to the player. I did this so that the code would be easier to change later–let’s say that I decide I want the player to put a watch into the box instead of a shoe. Now I just need to change the word “shoe” in the first line of the rule to “watch” and Inform will automatically produce the correct output (it’s the same if we change the box, too).

Hope this helps!

–Erik

Here’s a solution that works regardless of how the shoe got into the box, and has the door locked if the shoe is later removed from the box. This “fakes” a locked door by preventing the player to open the door when it’s locked.

[code]The Bedroom is a room. The red door is east of the Bedroom and west of the Living Room. The red door is a closed door.

The Kitchen is north of the Living Room. The box is a container in the Kitchen. The shoe is in the Kitchen. The player is in the Kitchen.

Instead of opening the red door when the shoe is not in the box:
say “A hollow voice says: ‘Please deposit all shoes into the shoebox before entering.’”[/code]

Many thanks, this is really useful.