hyperlinks in Glulx

Skip to first unread message


Jul 14, 2009, 1:39:08 PM7/14/09
Hi, everyone.

I'm trying to use hyperlinks with Glulx. Everything works fine with
exits management, as it is easy to substitute the input line entry
with the corresponding exit command. Identifiers for exits run from 1
to 1000.

Things get a lot more complex when you try to manage objects with
hyperlinks. I do this identifying the object number id through the
number for the link, storing 1000 + obj_id. When capturing the
hyperlink pres event, I just substract 1000 when the number is
greater than 1000, in order to get the object id. This works

I would like to retrieve the player line input, so of the player has
typed "examine ", then I would complete the input line with the name
of the object (I am doing this that way because I don't know how to
compose strings and make them work).

> examine
<<user clicks in the link for the photograph>>
> examine photograph
The photograph...

This however, does not work. I am only able to get the following;

> examine
<<user clicks in the link for the photograph>>
> photograph
Unknown verb

The code I am using is this one:

glk_cancel_line_event( gg_mainwin, abortres );
newcmd = manageHyperlinks( event-->2 );
cmdlen = PrintAnyToArray(
abortres-->0 = abortres-->0 + cmdlen;

glk_set_style( style_Input );
printAnything( newcmd );
glk_set_style( style_Normal );

glk_request_hyperlink_event( event-->1 );
return 2;

I am using abortres in order to retrieve the line input, but it does
not work. Various documents say that you can pass an array to the
glk_cancel_line_event() function in order to get the user input,
however, there are no examples, and I haven't found any reference
document. This is probably the part that fails. Any help?

David Kinder

Jul 14, 2009, 2:02:39 PM7/14/09
> I am using abortres in order to retrieve the line input, but it does
> not work.

The second argument to glk_cancel_line_event() has to be an event
structure, but it looks like you're assuming that it's an input
buffer. You can't get the input buffer from this call: all you can get
is an event telling you how much data the user had entered into the
buffer when you aborted. Something like:

Array abortEvent --> 4;

if (abortEvent-->0 == evtype_LineInput)
! Number of chars input in abortEvent-->2 ...

To actually get at the line input, you just use whatever buffer array
was originally passed in to glk_request_line_event(): For Inform 6,
this will usually just be the global array "'buffer" from parserm.h.


Rockersuke Moroboshi

Jul 18, 2009, 11:19:40 AM7/18/09
David Kinder escribi�:

David's event structure is probably the way to get it done, but I
couldn't make it work (just my fault, I got lost into this deep Glk
laberinyth thing ^_^'). I found this other rather dirty (and I mean
dirty XDD) workaround.

First of all, make sure buffer is absolutlely clean when player is
prompted to type any command:


[EmptyBuffer i;
for (i=4:i<=INPUT_BUFFER_LEN:i++)

Then this:

[HandleGlkEvent ev context abortres newcmd cmdlen i;
switch (ev-->0)
for (i=4:buffer->i:i++);
newcmd=" whatever";
return 2;

So, It takes a loop through buffer searching for the first unused
character and asumes that is the current input lenght. Then uses
PrintAnyToArray to insert the hyperlinked part (in this example "
whatever", note the space at the start) at that point and adjust the
lenght at the begining of abortres acordingly.

Yeah, ugly and dirty, not extensively tested, and likely to generate a
cascade of crashes in any unexpected circumstance... but seems to work!

Reply all
Reply to author
0 new messages