How to create a kind of supporter with a drawer?

I have several different desks (each with a drawer) in my game. Presently, each one coded as a supporter with code for opening the drawers and disambiguating between different drawers etc. This works fine, but there’s a lot of redundant code for opening & closing drawers, disambiguation etc. And I thought I should simplify things.

So my next thought was to create a kind, let’s call it a bureau, so that the code for opening a drawer within a desk is only written once. The code I wrote below compiles, but I can’t figure out how to refer to the drawer which is part of the bureau in order to open it. (To be more clear, if you open a bureau, it should open the corresponding drawer.)

[code]
A bureau is a kind of supporter. A bureau is fixed in place enterable. A drawer is a closed openable container and part of a bureau.

Instead of opening a bureau (called B):
try opening a drawer. [ that isn’t available]

Instead of closing a bureau:
try closing the drawer.

Instead of examining a drawer:
try opening the drawer.

Hotel Room is a room. “You’re at the San Moreno Inn, room 105.”

The hotel desk is a bureau in Hotel Room. On the hotel desk is a gun, a lamp. The hotel desk has description “Like you, the hotel desk is worn with cigarette burns and coffee stains. There’s a small drawer.”

The postcard is in the hotel desk drawer. The postcard has description “It’s a faded postcard with a picture of the San Moreno Mission.”[/code]
Unfortunately, opening the desk doesn’t work – it generates the message “That’s not available”. And it appears that the postcard is in an object called Hotel Desk Drawer which is not the drawer in the hotel desk.

What’s the best way to refer to the drawer of a bureau? I tried various ways and none would compile. Or am I barking up the wrong tree here?

Any advice is welcome. Apologies if this has been explained elsewhere, I looked in the docs and examples but came up short.

This seems to do what you have in mind:

[code]A bureau is a kind of supporter. A bureau is fixed in place enterable. A drawer is a kind of container. A drawer is usually closed. A drawer is always openable. A drawer is part of every bureau.

Instead of opening a bureau (called B):
try opening a random drawer that is part of B. [ that isn’t available]

Instead of closing a bureau (called B):
try closing a random drawer that is part of B.

Instead of examining a drawer (called D):
try opening D.

Hotel Room is a room. “You’re at the San Moreno Inn, room 105.”

The hotel desk is a bureau in Hotel Room. On the hotel desk is a gun, a lamp. The hotel desk has description “Like you, the hotel desk is worn with cigarette burns and coffee stains. There’s a small drawer.”

The postcard is in the drawer that is part of the hotel desk. The postcard has description “It’s a faded postcard with a picture of the San Moreno Mission.”[/code]

The differences are mainly:

– Using “random.”

– Making a drawer a kind.

– Making sure that a drawer is part of EVERY bureau.

– Getting the postcard into the right place.

I’d recommend redirecting “search desk” open the drawer and examine its contents.

Thanks much, this is terrific. I tried several variations but never got the syntax for “that is part of” right. One question remains for me: since there’s only one drawer, it seems odd to write ‘try opening a random drawer part of B.’ Why is “random” required in this case?

Even though you know there’s only one drawer, there’s no reason why the bureau couldn’t have more at any point during the game. The compiler has to take the possibility into account. Choosing a “random” drawer guarantees that the phrase is never ambiguous. (See also http://inform7.uservoice.com/forums/57320-general/suggestions/751522-programming-get-rid-of-a-random-when-it-s-obvi.)

You might want to take a look at The Automated Drawers by Emily Short Extension. It pretty much fully implements desks with drawers.

Hope this helps.