Darkness Witnessed [from chat]

Originally sent in LabBarAtory
Zed

I7 question: is there a clever way to, during the After or Report rules, answer the question: was the player in darkness at the beginning of this turn? I'm not thinking of anything better than setting a global variable.

This is odd: the Standard Rules have a global variable called darkness witnessed which starts the game false, becomes true the first time the player carries out looking in the dark, and then remains true for the rest of the game. It's never tested and there's no translation into I6 so it's not that it's being used there.

mathbrush

I always thought that After and Report completely ignored your state from before the action. I’ve had a lot of trouble with that recently.

Is there anything besides darkness that inform remembers in After and Report rules from before the action started?

3 Likes

I don’t really have a clever solution or explanation, and I might very well be missing something, but from cursory testing, it does actually seem to me that Inform updates the darkness status so late in the turn sequence that you can use “if in darkness” during a Report rule, for example.

As far as I can tell, it will reflect the state as it was at the beginning of the turn, even if the current action changed the status (either by switching on/off a light source or directly changing a room to lighted/dark).

In other words, unlike, e.g., “the number of things on a supporter” during a taking action, which does accurately reflect the number of things in the various stages of the action (n things in the Before stage, n-x things in the After stage, because the Carry Out stage caused the removal of some things in the meantime), the status of “in darkness” does not seem to change during the various phases of an action, and is only updated at the end of the turn sequence (probably in the “adjust light rule”).

Example:

The Lab is a dark room. "You can see the lab."

Carry out jumping:
	if the lab is dark:
		now the lab is lighted;
	otherwise:
		now the lab is dark;
			
Last report jumping:
	if in darkness:
		say "Player was in darkness at the beginning of this turn.";
	otherwise:
		say "Player was not in darkness at the beginning of this turn.";

Every turn:
	if in darkness:
		say "Every-turn: player was in darkness at the beginning of this turn.";
	otherwise:
		say "Every-turn: player was not in darkness at the beginning of this turn.";

Output:

Darkness
It is pitch dark, and you can’t see a thing.

>z
Time passes.

Every-turn: player was in darkness at the beginning of this turn.

>jump
You jump on the spot.

Player was in darkness at the beginning of this turn.

Every-turn: player was in darkness at the beginning of this turn.

Lab
You can see the lab.

>l
Lab
You can see the lab.

Every-turn: player was not in darkness at the beginning of this turn.

>jump
You jump on the spot.

Player was not in darkness at the beginning of this turn.

Every-turn: player was not in darkness at the beginning of this turn.

It is now pitch dark in here!

It works the same for a similar “Last report switching on a light source” rule (coming after a Carry out rule which turns on the “lit” status of a device).

2 Likes

!

Nice, thanks. I’ve got to admit, just trying it to see if in darkness itself provided the state at the beginning of the action didn’t occur to me.

But what I really wanted was to compare and contrast the beginning and the end. (Or that’s what I thought I really wanted.)

I had noticed that there isn’t a reveal any newly visible exterior analog to the reveal any newly visible interior rule: if you’re in a closed opaque container in a dark room and the container interior is lit and you open it, you get merely: “You open the (container)”, though, now that the container is open the room is visible.

That turns out to be a lot trickier than it sounds. Tracking in darkness at beginning and end doesn’t even work for this, 'cause the player isn’t in darkness in the beginning in this scenario. And Inform’s normal way to decide whether it needs to announce the room is if the player has transitioned from darkness to light.

As convoluted as it may be, this is the best I’ve come up with:

can-see-room is initially false.
the dummy is a thing.

To decide if (p - a person) is able to view the location:
 now the dummy is in the location;
 let result be false;
 if p can see the dummy, now result is true;
 now the dummy is nowhere;
 decide on result;

before doing anything:
 now can-see-room is false;
 if the player is able to view the location, now can-see-room is true;

Report opening an opaque container that encloses the player when can-see-room is false  (this is the reveal any newly visible exterior rule): 
 surreptitiously reckon darkness;
 if the player is able to view the location, try looking.

The reveal any newly visible exterior rule is listed after the standard report opening rule in the report opening rules.

The lab is a dark room.
The crate is a lit closed opaque openable enterable container. It is in the lab.
The player is in the crate.

test me with "open crate".

It’s incomplete inasmuch as it doesn’t attempt to deal with nested containers.

1 Like

ok, this does and doesn’t have the janky dummy object.

visibility-ceiling is an object that varies.

To decide what object is the visibility ceiling of the player:
  let h be the holder of the player;
  if in darkness, decide on h;
  while h is not a room and h is not a closed opaque container begin;
    now h is the holder of h;
  end while;
  decide on h;

Before doing anything, now visibility-ceiling is the visibility ceiling of the player.

Report opening visibility-ceiling (this is the reveal any newly visible exterior rule):
  surreptitiously reckon darkness;
  if the visibility ceiling of the player is not visibility-ceiling, try looking.

the reveal any newly visible exterior rule is listed after the standard report opening rule in the report opening rules.

The lab is a dark room.
the crate is a lit closed opaque openable enterable container. It is in the shipping container.
The shipping container is a closed transparent openable enterable container. It is in the lab.
the player is in the crate.
test me with "open crate".
2 Likes

This is interesting. I would say that you’ve discovered a worthwhile addition to the Standard Rules.

The behavior stems from the fact that there is no change in light/darkness in your scenario, so the announcement of light activity is not run by the adjust light rule. As you point out, the real question is whether there has been a change in the visibility ceiling, not a change in lighting status. It’s possible to make use of the existing visibility ceiling calculated global instead of tracking the status on your own, so the logic can be stripped down to

Report opening visibility ceiling calculated when not in darkness (this is the reveal any newly visible exterior rule):
	try looking.

The reveal any newly visible exterior rule is listed after the standard report opening rule in the report opening rules.

If the player was in darkness and that’s theoretically changed by the opening action, then this rule will be skipped but the room description will still be printed as part of the announcement of light activity. If the player is not in darkness then that status shouldn’t be changed, so only this rule will generate a looking action.

5 Likes

Or, yeah, sure, you could do it all in one line… :grinning: Nice one, Otis.