intfiction.org

The Interactive Fiction Community Forum
It is currently Tue Dec 11, 2018 3:09 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: I6: Hyperlinks in Glulx
PostPosted: Tue Nov 01, 2011 8:03 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 1619
I'm curious whether Glulx (and its interpreters) allows clickable text links to be used issue commands -- in an I6 game, not I7. This is a standard feature in T3, for instance. You can make the descriptions of the room's exits ("A path leads _north_.") into hyperlinks that, when clicked, will issue a relevant command ('go north').

There's an I6 extension called Markup.h, but I can't quite tell whether it allows this functionality. The documentation on it says:

! By itself, this tag [the a href= tag] is not terribly useful. It becomes useful only when
! the game has code in it to listen for hyperlink events, in order to attach
! actions to the links.

That seems clear. But I can't find a word in Markup.h about how one would add code to listen for hyperlink events and attach actions to them. So I'm left pretty much in the dark.

I do understand that not all interpreters will support links as a way to enter commands with the mouse. I also understand that Markup.h inconveniently forces one to number the href entities in the anchor tag. That's all okay with me. I'm just wondering, how would I handle the mouse button event?

Or is there another I6/glulx extension that does this, perhaps in a more straightforward way?

Thanks!

--JA


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Nov 01, 2011 9:51 pm 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 5832
In I6, you would write a HandleGlkEvent() function which catches event type 8.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Nov 01, 2011 10:11 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 1619
Hmm. Doe has some information on her site about how to use this, but I'm too tired tonight to make sense of it.

It's not entirely clear to me, for example, which of the words in the ev argument one would test to see if it's an event of type 8. Nor is it clear to me how one would find the value of href= in the anchor tag. Nor is it clear how one would then generate an artificial command line input from within HandleGlkEvent.

But as I said, I'm too tired. I'll take a closer look tomorrow. Thanks for the pointer.

--JA


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Nov 01, 2011 11:06 pm 
Offline

Joined: Thu Oct 22, 2009 4:31 pm
Posts: 1306
Gull also has discussion, with examples:

http://adamcadre.ac/gull/index.html

You could probably reverse-engineer the I6 by looking at the Basic Hyperlinks I7 extension.

--Erik


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Nov 03, 2011 11:38 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 1619
ektemple wrote:
Gull also has discussion, with examples:

http://adamcadre.ac/gull/index.html

Right now I'm looking at the Gull page on capabilities testing (http://adamcadre.ac/gull/gull-2c.html). That page offers this code:
Code:
if (glk_gestalt(gestalt_Graphics, 0)) {

...so I'm trying that in a simple test game, using Inform 6.31 (in Windows 7, if that matters). I'm using the -G flag, and I know the test game is compiling to Glulx, because I get an output file called MyGame1.ulx.

However, the compiler reports, "Error: No such constant as "glk_gestalt" and "Error: No such constant as "gestalt_Hyperlinks".

I've pretty much ruled out a typo in my code. One possibility that remains is that the Gull page has obsolete information. Another possibility is that I need to set a constant somewhere in addition to using the -G switch.

I'll keep poking at it, but if anyone has any suggestions, I'd appreciate hearing them!

--JA


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Nov 03, 2011 11:41 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 1619
Okay, got it. False alarm. Never mind. I needed to include Infglk.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Nov 04, 2011 12:22 am 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 1619
Here's a slightly more interesting question. I'm attempting to set up a text link so that when the player clicks the word "east" in the room description, the command "go east" (followed by a Return) will appear on the command line of the interpreter, with the expected result.

It's not working yet.

The link appears correctly in the terp. Here's the code that sets it up:
Code:
[link_set dir;
  switch (dir) {
   E_GOING: glk_set_hyperlink(E_GOING);
   print "east";
   glk_set_hyperlink(0);
   };
];

Room    study "Your Study"
  with  description [;
   print "There is a doorway to the ";
   link_set(E_GOING);
   " of this austere room.";
   ],
        e_to hallway;

Here's how I'm trying (and failing) to handle the click on the hyperlink:
Code:
Constant E_GOING = 1;
Constant W_GOING = 2;

[ HandleGlkEvent ev context abortres newcmd cmdlen;
      switch (ev-->0) {
         evtype_Hyperlink:
            glk_request_hyperlink_event(gg_mainwin);
         glk_cancel_line_event(gg_mainwin, 0);
         if (ev-->2 == E_GOING) {
            newcmd = "go east";
            cmdlen = PrintAnyToArray(abortres+WORDSIZE, INPUT_BUFFER_LEN-WORDSIZE, newcmd);
            abortres-->0 = cmdlen;
            glk_set_style(style_Input);
            print "go east";
            glk_set_style(style_Normal);
            new_line;
         }
      }
];

What this does is, when I click on the link, the words "go east" are printed on the line BELOW the prompt, the input cursor remains on the line with the prompt, and input is dead. The game no longer accepts typing input.

I'm trying to use the explanation on the Gull pages. I think I've copied the code exactly. Adam says those lines are supposed to do the job. But they don't. Since I can't find a reference to PrintAnyToArray in the DM4, I have no idea what it's doing. I'm stumped.

--JA


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Nov 04, 2011 3:19 am 
Offline

Joined: Mon Apr 18, 2011 3:14 am
Posts: 126
Location: Madrid, Spain
Now I can't remember how it worked (not hacked with glulx low level stuff for quite a long time!), but just in case it helps, a couple of years ago we were looking for a way to type a verb, like "examine", and then click on a link with an object and make the command "ex object" to be atomatically executed. As I'm reading that thread now, we were taking for granted that making a full command work from a link was actually the easy part!

It was here. Perhaps something in that thread helps.

_________________
English posts in my blog!


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Nov 04, 2011 12:06 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 1619
Thanks, rockersuke. I looked at the thread, and tried a couple of things that it suggested, but I'm still getting the same results as before.

I'm not sure what you're doing with this line:

for (i=4:buffer->i:i++);

Does that increment i until the value of buffer->i is zero? I think so. It wouldn't help in my code, so I guess I should ignore it.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Nov 04, 2011 3:08 pm 
Offline

Joined: Mon Apr 18, 2011 3:14 am
Posts: 126
Location: Madrid, Spain
Jim Aikin wrote:
Does that increment i until the value of buffer->i is zero? I think so. It wouldn't help in my code, so I guess I should ignore it.


That's right, that was for the specific subject in that thread.

Concerning your question, put the printing of the new prompt right before the glk_cancel_line_event() call and don't forget to finish it all with a return 2. It's working for me right now!

(well, almost, there's an ugly side effect if player types anything in the prompt before clicking on the link, but dealing with that is far beyond my very rusty glulx knowledge! ^_^')

_________________
English posts in my blog!


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group