I6: how to access prompt line (before enter)

Hi!

I’m trying to set a (real time) timer to periodically check out if the player has written anything on the command prompt (before hitting enter)… I tampered with DM4 exercises 131 & 132 and tried to access @input_stream 0 (keyboard) but I failed. Any suggestions?

I’m a noob with no answer for you.

But I am curious why you’d want to do this. When playing a text game, I expect that any text I type will not affect the game until I press enter to finalize it. It seems like that would throw a wrench in the immersion if I had any awareness of it–I might become self-conscious about the act of typing which isn’t something I’d normally focus on.

It might be worth reading the technical details about @aread. Otherwise post your code, so we can see what you’ve tried.

I just want to know if the prompt line is empty, like so:

_

…And if it is long enough (empty), the game would just pass a “wait” command, like this:

z
Time passes…

Why I’m trying this, is to have some intermediate solution to having some kind of “real time” fun with the game.
I’ll also look more into documentation and and pass some game code here at once its informative (its not yet!)
Thanks already!!!

Quick implementation:

! This "Replace" line must go before the Include Parser.
Replace KeyboardPrimitive;

! Put this routine after the Include Parser.
[ KeyboardPrimitive  a_buffer a_table res seconds;
	a_buffer->1 = 0;
	seconds = 0;
	while (1) {
		@aread a_buffer a_table 10 callback -> res;
		! If res is a return char, input is really over.
		if (res ~= 0)
			return;
		seconds++;
		if (seconds > 3) {
			a_buffer->1 = 1;
			a_buffer->2 = 'z';
			@tokenise a_buffer a_table;
			print "(I'm bored.)^";
			return;
		}
		! Now restart input.
	}
];

[ callback;
  rtrue;
];

The idea above is that the interpreter will interrupt line input once per second. (The 10 argument to @aread is in tenths of a second.) If this happens three times in a row, we manually push the string “z” into the input buffer and end line input.

If you wanted to get fancier, you could save the user’s partially-completed input somewhere and feed it back into the next line input.

Note that the input buffer can’t be read from inside the callback() function. The user’s text is not available until callback() has returned true (or the user has hit return).

Whether this is annoying to the player is not in scope for this comment. :slight_smile:

Great, thanks!
I tested the above routine – it failed almost exactly as my previous attempts:

It means the command “z” isn’t printed out on the prompt line, and/or isn’t registered as a command. I pasted your code quite blindly – I’ll try to do some thinking with it as soon as possible.

Hm. Works in Frotz and Gargoyle. Possibly I’m doing something wrong anyway. Will take a look.

Well if the routine runs good on your Frotz and Gargoyle, there has to be something wrong down here, with something I’ve done or haven’t done. I’ll try to reduce the bug-possibilities in my program text. Thanks again!