I6: Hyperlinks in Glulx

Cool! :smiley: That means it was working nicely for me 'cause my terp was acting in an illegal way! :stuck_out_tongue:

OK, as I said, I’ve been trying with this glk_set_echo_line_event() function (which I checked was supported in my Windows Glulxe)(remember to get the latest infglk.h, not the one in the IF Archive but the one in zarf’s github thing). Almost there…!

It happens that, as documented in the GLK 0.7.3 API specification that Ben linked (here), this function only works in subsequent line input requests… So the line break would be there when you catch the hyperlink event but won’t appear in subsequent turns… Of course in these subsequent turns ordinary behavoiur is overidden by this save you turn it off, which would then have an effect not in the current turn, but in the following ones…

Save I’m missing something, this make this feature very useful if you know in advance that your work is meant to be used exclusively in one or the other mode, but not if both are supposed to co-exist and you can’t predict wether the player is going to type or click.

Still I do hope I’m missing something…

As a practical matter, you would want to turn off the echo when the game starts. Then just print the player’s input after line input events - it comes back to you in the event struct - and discard it when you cancel the line input request.

Example code here; demo here.

Would it be pushy to ask someone to wrap this up in a nice I7 extension when it’s all ironed out? Because that would be great.

There are already three or four I7 extensions that offer the basic hyperlink functionality, including the ability to link a command that is different that the linked text (e.g., clicking on the text “north” to produce “go north”). What all of them are missing, though, is the new echo functionality to fix the default line break that accompanies a canceled input event. I second the request for an extension or a demo of that for I7…

–Erik

Aha, thanks!
That linked example is not in the format of an actual game and makes its glk calls with numbers instead of meaningful names (which are luckily mentioned after that in comments) so yeah, I’m having the mother of all headaches right now :laughing:, but I guess I have a working (and hopefully not based on an illegal feature if WinGlulxe) example:

[code]
!% -G
!% -D

Include “Parser”;
Include “Verblib”;
Include “Infglk”;

Object Room_01 “Room 01”
with
description
[;
print "You’re in Room 01. An exit leads ";
glk_set_hyperlink(1);
print “NORTH”;
glk_set_hyperlink(0);
print_ret “.”;
],
n_to Room_02,
has light
;

Object Room_02 “Room 02”
with
description “You’re in Room 2”,
s_to Room_01,
has light
;

[Initialise;
glk_request_hyperlink_event(gg_mainwin);
glk_set_echo_line_event(gg_mainwin,0);
lookmode = 2;
location=Room_01;
];

[HandleGlkEvent ev context abortres newcmd cmdlen;
switch (ev–>0)
{
evtype_hyperlink:
glk_request_hyperlink_event(gg_mainwin);
glk_cancel_line_event(gg_mainwin,0);

		newcmd="go north";
		cmdlen=PrintAnyToArray(abortres+WORDSIZE,INPUT_BUFFER_LEN-WORDSIZE,newcmd);
		abortres-->0=cmdlen;
		
		Command_printing();
		
		return 2;
	evtype_LineInput:
		Command_printing();
}

];

[Command_printing;
glk_set_style(style_Input);
glk_put_buffer(buffer+WORDSIZE, buffer–>0);
glk_set_style(style_Normal);
new_line;
];

Include “Grammar”;[/code]

It’s probably too late to help Jim, but I didn’t want to just forget about it. What it does is:

-Sets echo off at the begining of the game.
-Uses the line input event to manually print the contents of the player input (calling the Command_printing routine)
-After a click is detected, its command is also printed calling the same routine.

Seems to work, though I’ve hardly tested it! ^_^’ any contraindication or just something that could go wrong with this?

Far from being offended by this unintentional slight, I’m amused. I agree – I’m quite beyond help!

–JA