intfiction.org

The Interactive Fiction Community Forum
It is currently Wed Jun 19, 2013 11:32 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: Fri Nov 04, 2011 4:44 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 904
The printing of the new prompt? Sorry ... what line causes that?


Top
 Profile Send private message  
 
PostPosted: Fri Nov 04, 2011 6:22 pm 
Offline

Joined: Mon Apr 18, 2011 3:14 am
Posts: 106
Location: Madrid, Spain
There goes a very basic implementation of it. It doesn't even check the number of the link, just tries to execute "go n" when you click in the "NORTH" link of the room 01 description.

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);
   lookmode = 2;
   location=Room_01;
];

[HandleGlkEvent ev context abortres newcmd cmdlen;
   switch (ev-->0)
   {
      evtype_hyperlink:
         glk_request_hyperlink_event(gg_mainwin);
         
         glk_set_style(style_Input);
         print "go north";
         glk_set_style(style_Normal);
         
         glk_cancel_line_event(gg_mainwin,0);
         newcmd="go n";
         cmdlen=PrintAnyToArray(abortres+WORDSIZE,INPUT_BUFFER_LEN-WORDSIZE,newcmd);
         abortres-->0=cmdlen;
         
         return 2; 
  }
];

Include "Grammar";


As mentioned, its only drawback is the mixing of the "go north" new command line with anything the player had typed before clicking (which would go unnoticed if she hasn't typed anything, of course).

_________________
English posts in my blog!


Top
 Profile Send private message  
 
PostPosted: Fri Nov 04, 2011 10:20 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 904
Thanks. That was very helpful. I seem to have it working now ... almost. The only bit of piffle that remains is that when I click a link, the result looks like this:

Quote:
>
go east


I'm using a dummy object to print the command, and I'm sure that's horribly wrong, but it's the best I've been able to figure out. Here's what I have at present:

Code:
Object px "dummy"
   with short_name "dummy",
   has proper
;

[ HandleGlkEvent ev context abortres newcmd cmdlen;
      ! To suppress a compiler warning:
      context = 0;
      switch (ev-->0) {
         evtype_Hyperlink:
            glk_request_hyperlink_event(gg_mainwin);
         glk_cancel_line_event(gg_mainwin, 0);
         switch (ev-->2) {
            e_obj: newcmd = "go east"; px.short_name = "go east";
            w_obj: newcmd = "go west"; px.short_name = "go west";
            axe: newcmd = "x axe"; px.short_name = "x axe";
         }
         glk_set_style(style_Input);
         print (The) px;
         glk_set_style(style_Normal);
         new_line;
         cmdlen = PrintAnyToArray(abortres+WORDSIZE, INPUT_BUFFER_LEN-WORDSIZE, newcmd);
         abortres-->0 = cmdlen;
      };
      return 2;
   ];


If I don't use the four lines before cmdlen = PrintAnyToArray, the new command is never printed at all, even though it's carried out. So evidently I need to get rid of that kluge and figure out a way to stuff the actual command on the line with the command prompt. I have no clue where to look for a way to do that.

Adam Cadre, very unhelpfully, says this: "Now, you can either place that very phrase at the prompt to let the player know that's what's been done, or you can do something like this...." He then gives, more or less, the four lines that are printing my output in the wrong place.

<Sigh.>


Top
 Profile Send private message  
 
PostPosted: Fri Nov 04, 2011 11:29 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 904
No sooner do I solve that problem than I find I have a worse problem. When the player (at the moment, player = me) resizes the game window, a GlkEvent is generated, which means that HandleGlkEvent is called. This has the effect of repeating the last command, whatever it was -- and whether or not it resulted from clicking a link. I have no smegging idea how to prevent this, because nothing in my HandleGlkEvent code seems to be responsible for it. Here's what I have:

Code:
[ HandleGlkEvent ev context abortres newcmd cmdlen;
      switch (ev-->0) {
         evtype_Hyperlink:
            glk_request_hyperlink_event(gg_mainwin);
         switch (ev-->2) {
            e_obj: newcmd = "go east"; px.short_name = "go east";
            w_obj: newcmd = "go west"; px.short_name = "go west";
            axe: newcmd = "x axe"; px.short_name = "x axe";
         }
         glk_set_style(style_Input);
         ! print the command, whose text is now stored as the short_name of dummy object px:
         print (The) px;
         glk_set_style(style_Normal);
         new_line;

         cmdlen = PrintAnyToArray(abortres+WORDSIZE, INPUT_BUFFER_LEN-WORDSIZE, newcmd);
         abortres-->0 = cmdlen;
      default:
         context = 0;
      };
      return 2;
   ];


One would naively expect that a window resize event would fall through to the default case, which would do nothing. But no ... a new command is silently issued in the background.


Top
 Profile Send private message  
 
PostPosted: Sat Nov 05, 2011 12:03 am 
Offline

Joined: Sat Dec 22, 2007 11:52 pm
Posts: 773
Jim Aikin wrote:
Code:
[ HandleGlkEvent ev context abortres newcmd cmdlen;
      switch (ev-->0) {
         evtype_Hyperlink:
            glk_request_hyperlink_event(gg_mainwin);
         switch (ev-->2) {
            e_obj: newcmd = "go east"; px.short_name = "go east";
            w_obj: newcmd = "go west"; px.short_name = "go west";
            axe: newcmd = "x axe"; px.short_name = "x axe";
         }


Are evtype_Hyperlink and switch (ev-->2) supposed to be indented to the same level like that?


Top
 Profile Send private message  
 
PostPosted: Sat Nov 05, 2011 12:40 am 
Offline

Joined: Tue Apr 27, 2010 1:02 pm
Posts: 798
Jim Aikin wrote:
The only bit of piffle that remains is that when I click a link, the result looks like this:

Quote:
>
go east



You can change this behavior by taking advantage of one of the new Glk calls: glk_set_echo_line_event.

It lets you turn off the automatic printing of the player's input - but you are then responsible for printing something to the screen in its place. (You might also need to update your copy of infglk.h, depending on how recent it is.)


Top
 Profile Send private message  
 
PostPosted: Sat Nov 05, 2011 1:08 am 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 904
George wrote:
Are evtype_Hyperlink and switch (ev-->2) supposed to be indented to the same level like that?

Indentation is not significant in I6.


Top
 Profile Send private message  
 
PostPosted: Sat Nov 05, 2011 7:51 am 
Offline

Joined: Mon Apr 18, 2011 3:14 am
Posts: 106
Location: Madrid, Spain
Jim Aikin wrote:
The only bit of piffle that remains is that when I click a link, the result looks like this:

Quote:
>
go east




As I told you before, you must put the lines that write the new command at the prompt before calling the glk cancel line function, that's to say:

this
Code:
glk_set_style(style_Input);
print "MY NEW COMMAND HERE!";
glk_set_style(style_Normal);


goes before this:

Code:
glk_cancel_line_event(gg_mainwin,0);


And as I mentioned, the ugly side effect is that if the player types something before clicking the result could be like this (in the example she has typed "xyzzy", then, for any reason, changed her mind and clicked on the "NORTH" link)
Quote:
Room 01
You're in Room 01. An exit leads NORTH

>xyzzy

(now player clicks on NORTH before typing ENTER)

>go northxyzzy

Room 02
You're in Room 02.


I'm going to take a look to this glk set echo calls (I didn't know they existed! nice!) to see if they can help with this.

Jim Akin wrote:
No sooner do I solve that problem than I find I have a worse problem. When the player (at the moment, player = me) resizes the game window, a GlkEvent is generated, which means that HandleGlkEvent is called. This has the effect of repeating the last command, whatever it was -- and whether or not it resulted from clicking a link. I have no smegging idea how to prevent this, because nothing in my HandleGlkEvent code seems to be responsible for it. Here's what I have:


You're doing the "return 2" from the HandleGlkEvent main routine. You should put it in the evtype_hyperlink: case of the switch (ev-->0) switch. If not, you're returning "2" wichever the event is, which has the effect of canceling the current command line. And I miss the glk_cancel_line_event() call in your last code, which surely is causing some more adiotional chaos ^_^'.

_________________
English posts in my blog!


Top
 Profile Send private message  
 
PostPosted: Sat Nov 05, 2011 8:43 am 
Offline

Joined: Thu Oct 22, 2009 4:31 pm
Posts: 1138
rockersuke wrote:
As I told you before, you must put the lines that write the new command at the prompt before calling the glk cancel line function.


No, that's not legal. You can't print* when there's a line event pending, so the cancelation needs to happen first. The only way to prevent the line break is to use the set echo function that Ben mentioned.

--Erik

*Some interpreters will print text to the window while a line event is pending, but it is unambiguously out-of-spec.

_________________
Glimmr: Advanced Graphics for I7
blog | download | bug-tracker


Top
 Profile Send private message  
 
PostPosted: Sat Nov 05, 2011 11:21 am 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 904
ektemple wrote:
rockersuke wrote:
As I told you before, you must put the lines that write the new command at the prompt before calling the glk cancel line function.

No, that's not legal. You can't print* when there's a line event pending, so the cancelation needs to happen first. The only way to prevent the line break is to use the set echo function that Ben mentioned.

Thanks to everyone for offering suggestions. My reasons for wanting to use I6 were (a) I dislike I7, but (b) I want my game to be playable in a Web browser.

But the underlying impulse behind (b) is, I want the player to have a pleasant, modern experience. My foray into Glulx programming for I6 has convinced me that I'm unlikely to be able to provide that experience using these tools -- not without becoming so frustrated that I'll lose all interest in the project. The I6/glulx documentation is bad to nonexistent, and the coding requirements seem to be pretty much a mess.

At this point, it seems clear to me that using TADS 3 will be a much better alternative. Even if MJR doesn't have his Web server implementation up and running any time soon, the other aspects of the user experience will be more comprehensive, more reliable, and a whole lot easier to code. On balance, I6 loses; T3 wins.

Too bad. I like I6, and I was sort of looking forward to becoming an I6 virtuoso. YCAGWYW, but if you try some time, you just might find....

--JA


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

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 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