Glulx Input Loops
version 1/101121 by Erik Temple
Chapter: Modifications to Glulx Entry Points (the glulx input handling rules)
The Glulx Entry Points extension, which is a built-in extension and required by Glulx Input Loops to operate, provides hooks for authors to write event-handling rules for any type of glk event, whether player-generated (e.g., line input, hyperlink input) or not (e.g., timer, sound notification). After the initial (and minimal) library handling of an event, Inform passes the event type to the I6 function HandleGlkEvent stage. Glulx Entry Points then routes this to one of eight named rulebooks, one rulebook for each type of event. For example:
Glulx timed activity rules (timer-event)
Glulx line input rules (line-event)
Glulx character input rules (char-event)
Glulx hyperlink rules (hyperlink-event)
For two of these rulebooks--the hyperlink and mouse input rules--Glulx Entry Points allows the author to specify a "glulx replacement command" (indexed text variable), which if given a value will replace the player's command with the text given, as well as print it to the command line. This allows the player to, for example, use hyperlinks to issue commands.
Glulx Input Loops modifies the Glulx Entry Points approach in two ways:
First, Glulx Input Loops uses one single rulebook to rule them all--all types of glk events, that is. This approach allows a bit more breathing room for authors, and allows most of the structural logic that Glulx Entry Points implements using I6 code to be recast in I7 for easier accessibility. When HandleGlkEvent receives (from an input loop) the instruction to handle an event , Glulx Input Loops passes the event type, as a g-event value, to the "glulx input handling rules", a g-event parametrized rulebook. Hence, the author can write such instructions as:
A glulx input handling rule: <do something>
A glulx input handling rule for a char-event: <do something>
To avoid breaking existing code, the specific event rules in the rulebook call the corresponding rulebooks from Glulx Entry Points by default. We can override this globally by activating the "direct event handling" use option, or situationally using standard rulebook approaches. An example of one of the default rules:
Last glulx input handling rule for a hyperlink-event when the direct event handling option is not active (this is the redirect to GEP hyperlink rule):
abide by the glulx hyperlink rules. <--this is the rulebook provided by Glulx Entry Points
The second main modification to Glulx Entry Points's functioning is that, in Glulx Input Loops, *any* event type can (in principle) replace the player's command. There are two ways to make this happen. First, the manual option: If (and only if) we are using the glulx input rules, we can set the player's command directly (e.g., "change the text of the player's command to 'Arggh!'"), then end the rule with the "replace player input" rulebook outcome. This option is not available from the rulebooks created by Glulx Entry Points (e.g., the glulx hyperlink rules), because they do not have the necessary rulebook outcomes. Note that, if we want the replacement command to be printed to the command line as well, we will need to do this ourselves, with code something like this:
say "[input-style-for-glulx]<replacement text>[roman type]"
The other option, the automated option, is available from either the glulx input handling rules or the Glulx Entry Points rulebook, is to simply set the "glulx replacement command" variable to the text we want for the player's command. The replacement text will automatically be printed to the command line as well as substituted for the player's command. To use this option, we must *not* end the glulx input handling rules with "replace player input", as doing so will skip the automated command replacement.
There is in fact a third modification, but it is not expected to be particularly useful. The I6 Inform library includes the ability for HandleGlkEvent to instruct the input loop that calls it to continue as if the player entered no input at all. Glulx Entry Points does not provide for this, but we can do it in Glulx Input Loops by ending a glulx input handling rule with the "require input loop to continue" outcome.