glulxe/quixe with in-game links

I’ve been playing a little bit with the idea of how hypertext and parser fiction could be combined, which given my fondness for Inform 7, has led me to be noodling around with Quixe and with Erik Temple’s hyperlinks extension. Fun! But, say somebody selects a hyperlink text that links to “DESCRIBE FOO.” This prints in boldface on the next line. What I would like for is for it to print immediately next to the command prompt, as if it had been typed in. (Ideally, what I’m working toward here is the idea that subjects could either type the command or they could select something using a hypertext, and what ends up as the product on the screen would be agnostic to what had happened.)

I notice that “A Colder Light” produces output like it’s been typed, but doesn’t actually allow parser entry. I assume it just prints a "> " before echoing the command, although I’m not entirely sure how it accomplishes that. But, regardless, what I was thinking about would aspire to a play-it-either-way vibe, so having it to be a hyperlink-only game that produces output that makes it look like a parser game doesn’t work as well for me.

This is possible with the current Glulx (Glk) spec: you can set your game up so that when you cancel line input (for a hyperlink event), the input line is cleared and you can reprint anything you want there.

(Does not work perfectly in Mac Zoom, but I think Gargoyle, WinGlulxe, and Quixe are up to date.)

You can look at my source code for BTYT, which accomplishes this. It’s a bunch of ugly I6 inclusion, though, I’m afraid.

Oh, yeah, when I played with BTYT before I missed the part where it DOES EXACTLY WHAT I AM NOW TRYING TO DO. Thanks! So, having looked at the source code, I see all the I6 inclusions and try to get my head around them. Any chance of a hint as to the part I should be paying especially attention to for this?

In any case, have been having a good time playing around with Quixe and making different modifications to the .css templates you’ve put up. Thanks for those.

Let me see…

Look at all the sections wrapped in “if (EchoControlAvailable()) {…}” That’s what you need to do; the test checks whether the echo-control features are available, so the game won’t crash on an old interpreter.

The routine itself is:

[ EchoControlAvailable;
return glk_gestalt(17, 0); ! gestalt_LineInputEcho

Don’t try to cache the return value in a variable; call the function every time you need it. (If somebody copies a save file from one interpreter to another, you don’t want to be remembering an obsolete value in it.)

When the game starts up, after you open windows, call glk_request_hyperlink_event. Also there’s this:
if (EchoControlAvailable()) {
glk($0150, gg_mainwin, 0); ! glk_set_echo_line_event

In Keyboard(), or generally after reading a line of input: print the input line back, using the Input style. (The interpreter will always use the Input style for editing, so you need to match it when echoing, or you’ll get a strange style jump.)

HandleGlkEvent() contains the hook to react to a hyperlink-click event. You have to re-request hyperlink input on the window that got the event. The ischar argument is 1 if you’re in the middle of a hit-any-key-to-continue pause; we ignore the hyperlink in that case.

I’ve got a “if (~~EchoControlAvailable()) {…}” stanza there. If it’s an old interpreter, it’s already echoed the interrupted line input, because the call to suppress that isn’t supported. So we print a new fake input line, containing the link text. Two input prompts in a row is ugly, but the player will have some visual cue about what’s happened.

Note that my code path for responding to a link click is a little bit convoluted. This is the code in HandleGlkEvent(); ir pushes the link text into the input buffer, and then returns 2. This result is that KeyboardPrimitive() returns, just as if the player had hit Enter, and control winds up in Keyboard(). So the stanza in Keyboard() about “echo the input” covers both keyboard entry and hyperlink entry.

I’m not sure how Erik’s Hyperlinks extension is set up. You might have to rearrange my code a little, to match up with him.

Also note that my code tests LinksAvailable(), and works in a keyboard-only mode if the hyperlink feature is unsupported.