Quixe / Javascript

For my current project I’m trying to build a small custom point and click interface that interacts with Quixe.

I basically want this: if I click on a button in the footer of the HTML page, a command has to be sent to the command prompt and executed.

So far I’ve only managed to change the prompt’s text by resetting the .value of the input line. What I cannot work out is how to make the interpreter execute this command line automatically.

I (naively) tried to call GlkOte.submit_line_input, but of course that didn’t work. I’m not exactly a Javascript expert, so it might be something very trivial …

Thanks for any help!

Solved it.

How did you solve it?

I still don’t get this JS-closure thing entirely, but apparently it was a scope/closure problem. Since glkote is all contained in one function, you couldn’t call functions (like submit_line_input) inside the function from outside.

So I just opted for the ugly solution to change glkote.js directly (by inserting a few lines I needed into it).

It goes something like this:

Make a global variable inside the GlkOte function:

var gobutton_id = 'gobutton';

and then inside the accept_one_window function:

Event.observe(document.getElementById(gobutton_id), 'mousedown', function(ev) { submit_line_input(win, win.inputel, null); }); }

So every time the “gobutton” is hit, the current command line is processed. Seems to work so far.

It’s just not the most beautiful solution. I wish I could have left glkote.js intact and do everything from the outside by function calls. Didn’t manage to do that. But: hey, at least some progress. :slight_smile:

Since it’s Glulx, you could also just have hyperlinks on your text and style those to look like buttons using CSS, a la this: no need for any javascript at all.

@ErikTemple:

I’ve looked at the Sand-Dancer Sans Keyboard. This is brilliant! It’s almost what I was trying to do.

However I was also thinking about integrating an auto complete function for the input line. The interface should show you valid verbs as you type. That’s quite easy to do in JavaScript, hence my choice. At least unless somebody convinces me that this can be achieved in a different way as well.

Jon Ingold has implemented an in-game Glulx autocomplete that uses the game’s dictionary. It runs well in Quixe and does not require any hacking on the javascript.

Huh?! Must have overlooked that extension on the extensions page. It looks really nice, but a bit slow. I’ll look into it! Thanks.

You could try to trigger an enter keypress event in the input line, but I don’t know how to do it with pure JavaScript or Prototype. (Too bad Quixe doesn’t use jQuery.)

I know, I know…

(Switching to jQuery would solve multiple hassles at this point, but I just haven’t been on it. If somebody wants to write up a patch, that would be awesome.)

(Don’t feel constrained to keep supporting IE6…)

Doesn’t Parchment’s Quixe use jQuery? Could the implementation be moved from there to actual Quixe?

No, I think it’s patched up with some Prototype-and-jQuery-at-the-same-time recipe. That’s why the status line is broken, I figure.

If someone wants to do this I started porting Glkote to jQuery here: github.com/curiousdannii/glkote/commits/jquery

I haven’t changed the code to Quixe in Parchment, but maybe just the presence of jQuery is breaking things. I haven’t cared enough to fix it, because I want to some day write my own Glk implementation. I’m just not sure how to do that!