Secret feature in Basic Screen Effects

Dear Emily Short, please document this great feature I discovered by reading the source of Basic Screen Effects:

To decide what number is the chosen letter:
	(- GetKey() -)

(I was trying to implement a splash screen menu like the one in The Act of Misdirection. This not only waits for a key, but remembers which one was pressed. It’s returned as a number, but that’s no problem for anyone with access to an ASCII table, or a willingness to experiment minimally…)

How many other goodies are hiding in there?

Er, well:

Next time you have a specific request about an extension of mine, please email – it’s easy for me to miss forum posts when I’m busy.

Now, to the point: I don’t feel this is polished enough to be advertised in its current form. To be considered a feature rather than an internal method, it really ought to be returning text that the user can easily test against. I’m not going to document something that comes with a caveat that you need a ZSCII table in order to use it. (It’s somewhat munged ASCII it’s returning.)

If someone wants to write up some code that will do a better job of this feature, I’m happy to have a look; otherwise I can work on it When I Get Around To It, but my to-do list is pretty long right now.

FWIW, more for future users than for you: there is a splash screen extension on the extension site, by Jon Ingold, which does a lot of this nifty stuff automatically.


Thanks for the tip about Jon Ingold’s extension!

Here is the code I use to convert a keypress to an indexed text (the only appropriate I7 type, unfortunately) under Glulx:

[code]To decide which indexed text is (N - a number) resolved to an/-- indexed text:
if (N > 31 and N < 127) or (N > 160 and N < 384):[i.e., we have received printable input]
decide on “[char-code (N)]”;
decide on “”.

To say char-code (N - a number):
(- print (char) {N}; -)[/code]

The decide phrase takes a number (presumably a character code returned by VM_KeyChar) and returns that code as an indexed text if it’s found in the ASCII or Latin Extended A character sets. If the player has entered something else, whether an exotic character or a control key (e.g. return or arrow key), it returns an empty string. The same code works under z-code, though maybe there are interpreters that won’t allow character codes from the higher range (161 - 383)?

Anyway, you could build on Basic Screen Effects’s undocumented capabilities by adding something like this:

[code]Keychar is a number variable.
Keypress is an indexed text variable.

To get char input:
now keychar is the chosen letter;
now keypress is keychar resolved to an indexed text.[/code]

This gives the author access to the input in two forms. If we are interested in control key input (e.g., arrow keys), we can use the keychar variable to check against those codes, e.g.:

To decide whether (keychar - a number) is an arrow key: if keychar > -6 and keychar < -1, decide yes; decide no.

For printable input, we can just compare textually:

When play begins: while keypress is "": say "Press any key and I'll tell you what you pressed."; get char input; say "You typed: [keypress] (character code [keychar])."; if keypress is "": say "You pressed a control key. That's cheating. Try again![paragraph break]"; if keypress is "a" or keypress is "A": say "Good work, 'a' is the first letter of the alphabet!"

So, the basics of an author-friendly approach to char input are pretty simple. A full solution would probably have a number of decision phrases for different types of key, as well as a table of nonprintable input so that the author wouldn’t have to refer directly to character code numbers.

Anybody feel like carrying it the rest of the way?