Pausing the game when the player is writing

I’d like to pause the game when the player is writing (ie, when there are characters after the prompt).
How can i access to the buffer that contains the player’s command before he types a new line character ?
I’m using glulx

I assume you have some kind of real-time activity, using the Glulx timer events.

You can cancel line input, look at the input line, and restart line input. However, with the current spec, that will display extra copies of the input line.

I plan to change that (or rather, make the extra printing optional). However, even then, it will probably be a rocky user experience. You’d probably cause the user’s cursor to jump to the end, or just blink in an uncomfortable way.

On the whole, I think this is a bad approach. And speaking as a player, I would very quickly train myself to enter command with “enter-space” to pause every input immediately.

I’m not sure what you’re trying to do, but if your intent is simply to allow the player to continue with input that was interrupted by a real-time event, this capability is built into glk. This thread from a few weeks ago should be of some help:

On the other hand, if what you really want is character-by-character control over line input, you can in fact get that by recreating the line interface using character input, and it wouldn’t be all that hard to do–but it’s not to be recommended either. You won’t have a cursor, for one thing (though you can imitate one, I suppose), and your players will lose the ability to paste input to the command line.


I see what you did Erik. I had the same problem at some point. You can avoid it by just adding

When play begins: change the command prompt to “”.

Which is not that bad. Actually i prefer to play without a prompt, but i’d like to be able to customize the way it is printed : for instance printing it in red, so as to emphasize it. Is that possible ?

So i’m developing a real time game, and i’ve wondered how I should deal with time. Should the time of the game by synced to the real time (like in animal crossing) or should I allow it to be different ? (like in GTA where 1 min = 1 s).
So far I haven’t really chosen, but I think a pausing-when-the-player-is-writing functionality is something my extension should include. For example:

[code]The Real Time rules is a rulebook.

A glulx timed activity rule
(this is the real time stage rule):
___________unless the player is typing:
______________________follow the Real Time rulebook;

To decide whether the player is writing:
___________if the input buffer length is 0, decide no;
___________decide yes;

To decide what number is the input buffer length:
___________(- SOME_I6_VARIABLE -).[/code]

my I6 variable being updated within the function that converts keystrokes to ASCII :
if the key typed is the delete key, decrement the I6-Variable,
else if the key typed is the newline key, I6-Variable = 0,
else increment the i6 variable.

I though this function was the VM_KeyChar function, but it doesn’t seem to be called by the system…

Also I’m not sure to understand what gg_mainwin and gg_event are in
glk_cancel_line_event(gg_mainwin, gg_event); stored_buffer–>0 = gg_event–>2;

gg_mainwin is the story window; you are cancelling line input in this window.

gg_event is an array of four values. It gets filled in with information about the line of input that you’re cancelling.

Well, the command prompt really isn’t why I linked to that thread. zarf mentioned that one way to do what you want (only really practical in the future, once the line-break-on-line-input-cancel behavior is under author control) is to cancel and restart line input (using a timer to decide when to cancel). The code I linked includes the phrases you would need to do that–there’s some relatively obscure I6 that needs to be done to retain the state of the buffer when the line event is canceled, and to repopulate the buffer when a new line input is requested (thanks again to zarf for his help figuring it out!).

Line input and character input are two mutually exclusive modes in Glulx. The conversion of keystrokes in line input is performed by the interpreter, and can’t be affected by the author–nothing is put into the line input buffer until the player presses return, or line input is canceled.

VM_KeyChar, on the other hand, handles character input (char input). With char input, the library reads in a single keypress and returns the character code. (This is usually used for “Press any key to continue” input.) If you’re really attached to the idea of pausing the timer while the player is typing, you could do it, as I mentioned above, by recreating the library’s line input functionality using char input. This has definite downsides.

You could also do it more hackily by accepting the first character of any input as char input, pausing your timer, inserting the character entered into the line input buffer, and then requesting line input.

But, to be honest, I don’t understand the reasoning behind wanting to pause the timer while the player is typing. Why pause it for typing but not for reading? The player will always be able to cheat your timer and, by typing a character immediately when the command prompt appears, fool the game into not advancing the clock at all.