How to make and reveal hidden exits?

I’m working on a game that has a few secret passageways scattered throughout. One thing that I’m struggling with is the design for hidden exits and doors. I’m trying to achieve an effect where an exit is hidden from the player. The exit should not be listed when the user types exits, and it should not be included when using code such as this:

(current player $Player
($Player is $ $Loc)
(collect $Dir)
  *(from $Loc go $Dir to room $)
(into $Exits)

Here’s some boilerplate code I’ve been playing around with to try and get this to work. It seems like I should be able to use the special (door is revealed) rule to show/hide an exit like this,

(if) (door is revealed) (then)
  (from * go #west to #bedroom)

but I can’t get it to work. I have a feeling I’m missing something pretty basic here.

  (now) (#player is #in #chamber)
  (look #chamber)

(current player *)

(room *)
(singleton *)
(name *) a stone chamber
(look *)
  A stone chamber without any exits.
  A lever is on the wall though.

%% This exit should be hidden by default.
%% I'd like to do something like this.
%% (if) (door is revealed) (then)
%%   (from * go #west to #bedroom)
%% (endif)
(from * go #west to #bedroom)

(item *)
(switchable *)
(name *) metal lever
(dict *) switch
(* is #in #chamber)

%% Custom actions.
(after [switch on *])
  You hear the grinding of stone.
  (now) (door is revealed)
(prevent [switch off *])
  Not when you've revealed the exit! You can't stay here forever.
(instead of [pull *])
  (try [switch on *])

(room *)
(singleton *)
(name *) The king's bedroom
(look *)
  The bedroom is dominated by a large, carved four-poster bed.
(from * go #east to #chamber)

%% Custom grammar for "flip lever"
(understand [flip | $Word] as [switch $Obj])
  *(understand $Word as single object $Obj)

Thanks for any help!

1 Like

There’s an extension by Gavin Lambert called Secret Doors. I’ve used it, and it works great.

Or you could invent a secret door that isn’t a standard inform door-- a fake door that acts like a real one. I never use Inform doors anymore-- I fake all of them so I can get them to behave how I want.

To have a conditional exit, you can simply make the rule defining the exit fail.

(from #room1 go #west to #room2)
    (door is revealed)

So if (door is revealed) fails, the exit won’t “exist”.

Note that (door is revelead) is not special in your case, it’s just a dynamic flag you created (i.e. similiar to a global boolean). You might be mixing it up with ($ is revealed), which is something else unrelated to what you want to do.

@AmandaB Unfortunately for you, this post is about Dialog, not Inform 7. But thanks anyway!

1 Like

Oops! Sorry.

Wonderful, thank you Nathanaël

I knew it had to be something simple that I was overlooking. Much appreciated.

1 Like

By the way, to add “flip object” as a synonym of “switch object”, you can simply write:

(grammar [flip [object]] for [switch $])

Instead of using the “understand” rule. It a bit simpler.