I’m trying to figure out a good way to allow real-time events to interrupt command line input. For example, you have a bomb wired to go off in 30 seconds–every second, the status line is updated to show the time remaining. If the player can’t stop the bomb in time, it goes off. When it does, we want the text announcing the bomb to print a blank line at the command prompt to show that the command was interrupted, then (if the player survives) request new input:
It’s that last part that’s the rub. It’s illegal in Glulx to print text to a window while input is being accepted, so you need to cancel the line event at the first prompt in order to call the bomb’s output routine. And that’s easy enough, but once canceled, how do we restart line input nicely? The timed event has intervened and we are now running a new rulebook (in the I6-level HandleGlkEvent routine), but presumably when this rulebook ends, we will be back in whatever routine we were in while the game was awaiting input, but with no input. The result is that the game freezes: with no input, the player is unable to do anything. (Note that the game doesn’t crash–there’s just no way to enter input.)
Does anyone know how to get the parser to re-request input? Would it be necessary to hack the parser/keyboard routines with checks for a flag, like these guys did a decade ago? (In other words, pepper the keyboard routines with checks for a flag set by the real-time event; if ever the flag is true, immediately return to restart the process? I’d like to do this without hacking the parser, but if it’s necessary I guess it’s necessary!
Here’s some code, in case it helps:
[code]Include Glulx Entry Points by Emily Short.
Test is a room.
To decide whether the event is text-producing:
decide on produces-text.
Produces-text is a truth state variable.
The button is a device in Test.
Instead of pushing the button:
say “Click. Is that a clock ticking?”;
start a 2000 millisecond timer.
A glulx timed activity rule:
if the reading a command activity is going on:
cancel line input in the main window;
cancel character input in the main window;
say “[line break][line break]”;
say “Boom! There’s an explosion somewhere else in the complex.”;
stop the timer;
[Do something to get a new prompt;]
now produces-text is false;
To start a/-- (T - a number) millisecond/ms timer:
(- if (glk_gestalt(gestalt_Timer, 0)) glk_request_timer_events({T}); -)
To stop the/-- timer:
(- if (glk_gestalt(gestalt_Timer, 0)) glk_request_timer_events(0); -)[/code]
Any ideas welcome!
Thanks,
Erik