Hypothetical Questions by Jesse McGrew


The basic operation of this extension is to run a phrase, then consider a rule or rulebook, and finally undo the phrase while preserving the outcome of the rule. For example:

This is the check player's pulse rule:
     if the game ended in death, rule fails; otherwise rule succeeds.

...

hypothetically try drinking the poison and consider the check player's pulse rule;
if the rule failed, say "Drinking the poison would be a bad idea.";

Here, the phrase we're hypothetically running is "try drinking the poison". The "check player's pulse" rule tests whether the player has died after drinking the poison. The extension then undoes the drinking action, but remembers the decision made by the check player's pulse rule.

In fact, we can hypothetically run any phrase, not just an action:

To drink everything:
     repeat with X running through things that can be touched by the player:
         try drinking X.

...

hypothetically drink everything and consider the check player's pulse rule;

The player won't see any messages about things that happened hypothetically, because this extension captures the text printed during hypothetical execution. Our rule can check "[the hypothetical output]" to see what was printed. (If the rule itself prints anything, though, the player will see it.) For example:

This is the check for interesting events rule:
     if "[the hypothetical output]" exactly matches the regular expression "\s*Time passes\.\s*", rule fails;
     otherwise rule succeeds.

...

hypothetically try waiting and consider the check for interesting events rule;

The maximum length of captured text is 256 characters by default; anything more will be thrown away. We can change this with a use option:

Use hypothetical output length of at least 1024.

Section: Caveats

This extension requires an interpreter that supports undo. To the best of the author's knowledge, every Glulx interpreter supports undo, so this isn't much of an issue.

Avoid hypothetically running any code that uses undo, or that hypothetically runs some other code in turn.

If the hypothetical code changes the Glk library state (opening windows, closing streams, moving the cursor, etc.) -- or the FyreVM channel state, when running on FyreVM -- these changes will not be rolled back when hypothetical execution is finished.

Section: Change Log

Version 2 fixes a paragraph spacing issue where multiple hypotheticals would cause extra line breaks; and prevents hypothetical changes to the random number generator, I/O system, and string decoding table from leaking back into reality.

Version 3 was updated for compatibility with 6L38 by Emily Short.

Version 4 was updated for compatibility with 6M62.

Example: * A Sense of Adventure - Letting the player know what will happen if he picks up nearby objects.

Here we use the extension to the give the player a bit of clairvoyance. After moving to another room, we hypothetically try picking up every object in the location, then test whether the player would have died, won the game, or gained points. If so, we print an appropriate message.

"A Sense of Adventure"

Include Hypothetical Questions by Jesse McGrew.

Use scoring.

The maximum score is 5.

Hallway is a room. "This hall leads east and west. There's also a door to the south."

Trophy Room is east of the hallway. "This room is absolutely jam-packed with trophies. The exit is to the west."

A golden idol is in the trophy room. After taking the golden idol for the first time, increase score by 5.

Danger Zone is west of the hallway. "This room is full of various hazards. If you know what's good for you, you'll leave to the east."

A cursed idol is in the danger zone. After taking the cursed idol: say "As you pick up the idol, you feel an evil presence sucking the life force out of your body."; end the story.

Winners' Lounge is south of the hallway. "This is where winners hang out. A door to the north leads back to the hallway."

The Mask of Victory is here. "A strange mask is hanging on the wall here. A sign beneath it simply states: 'The Mask of Victory'." After taking the Mask of Victory, end the story finally.

Report going:
     hypothetically take everything and consider the player's fate rulebook;
     if the outcome of the rulebook is:
         -- the player dies outcome: say "You sense an ominous presence. Better be careful picking things up in here!";
         -- the player wins outcome: say "You sense your victory is at hand!";
         -- the player scores outcome: say "You sense a potential profit. Better grab everything you can!".

To take everything:
     repeat with X running through things in the location:
         try taking X.

Player's fate is a rulebook. The player's fate rulebook has outcomes player dies, player wins, player scores, and nothing noteworthy (success - the default).

A player's fate rule when the story has ended finally: player wins.

A player's fate rule when the story has ended: player dies.

A player's fate rule when the score is greater than the last notified score: player scores.

Test me with "w / e / e / get idol / w / s / get mask".