Making a door closed

hi,

how can i make a door close after entering the door?

You could try this (which has only been very lightly tested):

After going through a door (called passageway): say "(closing [the passageway] behind you)"; Try closing passageway; continue the action.

Or you might want to generate a different set of messages.
“continue the action” seems to be necessary for you to look after going through.

“Try closing the noun” doesn’t work because Inform thinks the noun is the direction you just went.

Hope this helps!

Matt

and for locking?

You can use the “now” structure (see manual chapter 8.11): now the passageway is locked.

“now” works for both. but why “try” won’t work?

Which try? If you had “try locking the passageway,” it won’t work because there’s no “locking” action (unless you’ve defined one yourself or use an extension that does that), only “locking it with”. “Try” means that the player character actually tries the action in the game as if the player would’ve typed it and it might or might not succeed, depending on the situation. “Now” makes the change directly and it doesn’t need an action attached to it.

got it! thanks.

You can get “try” to work thus:

[code]Definition: A thing is player-carried if the player carries it.

After going through a door (called passageway):
say “(closing [the passageway] behind you)”;
Try closing passageway;
if passageway is closed:
if the player carries a thing that unlocks passageway:
let locker be a random player-carried thing that unlocks passageway;
say “(locking [the passageway] with [the locker])”;
try locking passageway with locker;
continue the action.[/code]

(There’s probably a better way to handle “player-carried.” I had to do that because Inform is tetchy about handling multiple that-clauses; if you type “let locker be a random thing that unlocks passageway that is carried by the player,” it thinks “that is carried by the player” modifies “passageway.” This is one of the cases where I think the natural-language syntax works a bit poorly.)

One advantage this might have over the “now” phrasing is that the “now” phrasing will lock the door even if the player doesn’t carry the key – so it’ll be easy for players to lock themselves out. Or maybe that’s what you want. Another warning is that players often resent having to manually unlock and open every door they go through. (At least I do.) Making every door close and lock automatically could aggravate that. But if there’s a horde of slavering zombies on the other side of the door, it’s a good thing.

Matt

I’m wondering what the intentions are on this. Is the original poster trying to set up a game in which players automatically close and lock every door they go through? The more likely scenario is that sepehr is asking how to close and lock a particular door after the player goes through it. (I’m making an assumption here so please correct me if I’m wrong.)

If that is case, you really don’t want to use the ‘try’ phrases, because that is making the player character perform the actions.

After going through the haunted door:
    say "After you step into the room, the heavy wooden door slams shut and you hear a soft click.";
    now the haunted door is closed;
    now the haunted door is locked.

the story is so that when you get into a room, the door behind you closes and you have to escape.It’s just for the beginning of the game!

Oh, then you definitely want Mick’s approach. I’ve been talking about something that makes the player automatically close and lock every single door in the game behind him.