Dear Intermediate,
Certainly. Here’s an example that will demonstrate two techniques, both of which kind of involve the game sort of “talking to itself.”
The Vorple Hyperlinks extension lets us make hyperlinks to web addresses, hyperlinks that activate JavaScript commands, and hyperlinks that essentially type a command into the prompt and hit Enter for you. This example demonstrates the third version:
"The Heavy Door" by Ryan Veeder
Include Vorple Hyperlinks by Juhana Leinonen.
[This causes the base Vorple extension to be included as well.]
Release along with the "Vorple" interpreter.
Security Checkpoint is a room.
Vault is a room.
The heavy door is a closed door.
The heavy door is inside from Security Checkpoint and outside from Vault.
Instead of opening the closed heavy door, say "The door is too heavy to open!"
The button is in Security Checkpoint. The button is fixed in place.
Initial appearance of the button is "There is a [pushable button link] here."
To say pushable button link:
place a link to command "push button" reading "button".
Instead of pushing the button:
say "You push the button, and the heavy door opens.";
now the heavy door is open.
When the player clicks the hyperlink reading “button,” the command >push button will appear in the transcript and the action will take place. Visually, it looks exactly like the player typed that command! Can you think of anything clever you could do with this???
The other way you can make Vorple “tell itself” a command is with the “queueing” function of the Vorple Command Prompt Control extension. To “queue” a command is to make the game process that command. The documentation explains how using this extension to queue a parser command "take inventory", without showing the command
is basically identical to using the native Inform 7 technique of try taking inventory
and so by itself this syntax is not very useful.
Within the source of the Vorple Command Prompt Control extension, we see that queue a parser command "wear stockings" without showing the command
gets translated into JavaScript with the line:
execute JavaScript command "vorple.prompt.queueCommand('wear stockings',true)"
(The true
indicates that we don’t want the command itself to show up in the game transcript.)
Again, by itself, this is kind of the same thing as the Inform 7 code try wearing the stockings
. But, because we have escaped from the Inform 7 environment into the realm of JavaScript, we can use additional JavaScript syntax to do more interesting things. For example, what we’re going to do now is make the heavy door slowly swing shut, in real time.
If you were going to make this door close by itself on a turn-by-turn basis, you’d probably write something like:
Openness is initially 0.
Instead of pushing the button:
say "You push the button, and the heavy door opens.";
now the heavy door is open;
now openness is 4;
Every turn while openness is greater than 0:
decrement openness;
if openness is 3:
say "The door is beginning to close.";
else if openness is 2:
say "The door is halfway closed!";
else if openness is 1:
say "The door is almost closed!";
else if openness is 0:
say "The door swings shut.";
now the heavy door is closed.
To do this in real time, the principle is the same, except instead of referring to “every turn,” we’re going to invoke a secret action that we can tie to the actual passage of time.
Openness is initially 0.
Button timing is an action applying to nothing.
Understand "xxxbuttontimexxx" as button timing.
Carry out button timing:
if the heavy door is open:
decrement openness;
if openness is 3:
say "The door is beginning to close.";
else if openness is 2:
say "The door is halfway closed!";
else if openness is 1:
say "The door is almost closed!";
else if openness is 0:
say "The door swings shut.";
now the heavy door is closed.
Notice that no Vorple nonsense has occurred yet. To be clear, in Inform 7 terms, “xxxbuttontimexxx” is a regular old input the player could type at any moment, triggering the “button timing” action that exists only to advance the story of the door closing. The text “xxxbuttontimexxx” will not appear in the game, though. There is no reason to expect the player to type it. Instead, we will make the game type it to itself on a schedule we define.
All we have to do is add to the “pushing the button” rule:
Instead of pushing the button:
say "You push the button, and the heavy door opens.";
now the heavy door is open;
now openness is 4;
execute JavaScript command "setTimeout(function() {vorple.prompt.queueCommand('xxxbuttontimexxx', true);}, 2000)";
execute JavaScript command "setTimeout(function() {vorple.prompt.queueCommand('xxxbuttontimexxx', true);}, 4000)";
execute JavaScript command "setTimeout(function() {vorple.prompt.queueCommand('xxxbuttontimexxx', true);}, 6000)";
execute JavaScript command "setTimeout(function() {vorple.prompt.queueCommand('xxxbuttontimexxx', true);}, 8000)";
These new lines contain the “queue a command” JavaScript syntax that we’ve seen already, but each queued command is nested in a setTimeout command. And all that command does is tell the browser, "I need you to fire off this nested command after this many milliseconds." The number at the end is the number of milliseconds.
(Because we’re directly referencing the JavaScript methods as defined in vorple.js or wherever, we don’t actually have to include the specific Vorple Command Prompt Control extension for these purposes.)
After you push the button, the game will wait two seconds, and then “secretly type in” the command “xxxbuttontimexxx,” causing the button timing action to occur. And after two more seconds, the same thing will happen again. The way each instance of the action is resolved gets handled at the Inform 7 level.
Try it out!
So, how does the shooting gallery in Little Match Girl 4 work? Starting the minigame “launches a bunch of targets,” putting them into play so that the player can start trying to >SHOOT TARGETS. But at the same time the minigame starts, we “schedule” a “secret action” for a few seconds later. That secret action represents all the targets falling to the ground and the minigame being over.
And you can use these same principles to sync text with music. LIKE IN THAT GAME I MADE.
Thank you for your question.
A caveat: These “secret actions” are regular plain old actions, as far as Inform 7 knows. That means that they increment the turn counter, trigger “every turn” rules, etc. But if your scheduled secret actions start interfering with your “every turn” rules, you’ll probably notice something screwy is happening pretty quick.