Changing the scope to see into other rooms works, strangely

Code supplied from the recipe book; edited down:

[code]Street in Kolonaki is a room. “There is a single round table out on the street here, and a window more or less at knee level looks down into the Olive Tree Gyro Shop, which is partly basement.”

Olive Tree Gyro Shop is inside from Street in Kolonaki. Kostis is a man in the Gyro Shop.

The can’t reach through closed window rule is listed instead of the can’t reach inside rooms rule in the reaching inside rules.

This is the can’t reach through closed window rule:
let reaching through the window be false;
if the container in question is a room and the container in question is not the location:
if the container in question is the Street and the location is the Olive Tree Gyro Shop:
now reaching through the window is true;
if the container in question is the Gyro Shop and the location is the Street:
now reaching through the window is true;
if reaching through the window is true:
if the window is closed:
say “You can’t reach through the closed window.”;
deny access;
otherwise:
allow access;
otherwise:
say “You can’t reach into [the container in question] from here.”;
deny access.

After looking when a room (called the next room) is adjacent:
try examining the next room.

Instead of examining a supporter, say “On [the noun] [is-are a list of things on the noun].” Instead of examining an open container, say “In [the noun] [is-are a list of things in the noun].”

The window is a backdrop. It is in the Street and the Shop. The window can be openable. The window can be open. The window is openable and closed. Instead of searching the window in the Street: try examining the shop. Instead of searching the window in the Shop: try examining the street.

Understand “examine [any adjacent room]” as examining.

Instead of examining a room:
say “Over in [the noun], you can see [a list of visible things in the noun].”

After deciding the scope of the player:
if the player is in the Street, place the Shop in scope;
if the player is in the Shop, place the Street in scope.
[/code]
Added code:

The storage room is west of the Gyro Shop.

Every turn:
	if Kostis is in the Gyro Shop:
		try Kostis going west;

This is the built in example to demonstrate a window that can be seen through and also reached through.

I’m using this code in a situation where the player is locked in a prison cell and can reach various objects through the bars of the cell.
The problem arises when an NPC enters or leaves the other room from where the player is.
When the NPC leaves the room to the west, the report rule prints out:

The problem seems to be some combination of the intermediary room being in scope which makes the third room “adjacent”. Any possible insight or work-around would be appreciated.

I would try intercepting the report rule with an after rule.

After an actor going from an adjacent room: if the room gone to is not the location, do nothing; otherwise continue the action.

I would instead use the “person” object because it handily excludes the player from ignoring their own going froms (which overrides room descriptions).

After a person going from an adjacent room: if the room gone to is not the location, do nothing;

This only partially solves the problem, because now there is no report at all when a person is leaving sight.
Preferably, I’d want it to say something about the NPC leaving when they go away.

Ah, right. Actually, there’s a few other things that could use tweaking. The “after” rules don’t check to see if the action was visible to the player, so they’ll fire anytime anyone moves from any adjacent room, even if the adjacent room is not in scope. So, unless you plan to have a lot of areas where adjacent rooms will be placed in scope, it’s probably best to just make the rule apply to the specific rooms in your game.

After someone going from the Prison Hallway when the location is the Jail Cell: if the room gone to is the location: say "[The actor] enter[s] [the room gone to] from [the noun]."; otherwise: say "[The actor] leave[s] [the room gone from] to [the noun]."

After scratching my head for a while, I’ve come to the conclusion that your solution is the most practical.

If there were some way to check if a room was visible or in scope, you could amend something like this to work:

After someone going from an adjacent room [(which is visible to the player / in scope)]: if the location of the actor is not the location of the player: say "[The actor] leave[s] [the room gone from] to [the noun]."

Does anyone know a way to check if a room is visible to the player or in scope?

You have to define it, because the standard “visible” adjective only applies to things, not rooms.

Definition: a room is visible rather than invisible if the player can see it.

Note that a room is never in scope unless you write an explicit scope rule for it. In particular, just being in a room doesn’t put the room in scope! So, depending on your needs, you might want to write:

Definition: a room is visible rather than invisible if it is the location or the player can see it.