Parchment / quixe + JavaScript?

Can anybody point me to any tutorial/example/resource on doing any sort of tricks to add custom JavaScript code that somehow hooks up with what happens in an Inform7 game played in a browser?

I’m thinking of doing something for the 10 room minicomp and I’m thinking maybe there is some way to do something fancy with a map image. Maybe some jquery stuff… But are there any particular ways of hooking it up that I don’t know about?

I don’t know of an example of this, although it’s technically possible.

The only feasible way to do it right now (that I know of) is to monitor the story text for special characters and act when they appear. See this thread for an example.

I’m working on an actual solution, but it takes at least a couple of months before it’ll be available.

Cool, that’s sort of what I was thinking of – neat hack!

I’ll see what I can come up with and report back if I do figure something out…

I think the best solution, for both Z-machine and Glulx, is to use streams. It would work very similar to printing to a memory stream, except that when you turn the stream off it would eval() the text, and then write back what eval() returned.

If you’re able to limit yourself to the Z-machine then I could make a very quick implementation of this, it’s only 5 minutes work. (I would want the proper implementation to be Web Worker compatible, but seeing as Parchment doesn’t use them yet I could take a short cut now.) If you need Glulx then someone else will need to hack Quixe, I’m not yet familiar enough with its code.

Okay I’ve pushed the code to a new branch: github.com/curiousdannii/parchm … evalstream

Specs and tests are in my if repository.
curiousdannii.github.com/if/zspec12.html
github.com/curiousdannii/if/raw … stream.inf

Hi, I just played around with this and here’s a little javascript that grabs the current room name from the status line. You don’t need to do anything to the parchment.min.js or anything special in inform, (or muck about with I6), just “release along with an interpreter”, add this to play.html and you’re good.

Here I just output it into a div, but my intent is to use this to indicate where I am on an a visual map. This is mostly comments, and perhaps not the best way to do this. I’m trying to do this step by step so anybody can follow, hopefully this can spark some ideas.

The “$” stuff is jQuery, which is already there with your Parchment installation.

/* 
 * dynamap.js 0.0.1  
 *
 * This is a javascript that grabs the current room name from the Parchment play.html. 
 * 
 * 1. Add the script to play.html with this line in the <head>:
 *   <script src="dynamap.js"></script>
 *
 * 2. Add a div like this, for example right under the <div class="smalltitle">...</div> line:
 *   <div id="myOutput"></div>
 */

function dynamapUpdate() {
	// grab the status line
	var grab = $("div#top-window span").text();

	// extract the room name from the status line: 
	// the regexp should be like this, without quotes, surrounded by slashes
	// \s*    -- any number of white spaces, followed by...
	// (.*?)  -- anything, in a matching group meaning this is what we look for, followed by...
	// \s\s   -- two spaces
	var myRegexp = /\s*(.*?)\s\s/; 
	var match = myRegexp.exec(grab);
	var room = match[1];

	// output the room name
	$("div#myOutput").html(room);
}

// start automatically:
window.onload=function(){
	setInterval("dynamapUpdate()", 500); // interval in ms
}

maybe make some change did this, via a custom hack in Parchment that danii did for me back in mid 2010 I think (yeah, looks like it’s using “build 2010-06-22” of Parchment). But the technique stopped working in newer versions of Parchment. The relevant bit of code to make this work on the Inform 7 side, at least, is:

[code]
Include (-

Constant HDR_SPECREVISION $32;

[ Gestalt zid gid arg val;

! Check a gestalt value
#Ifdef TARGET_ZCODE;
	@"EXT:30S" zid arg -> val;
#Ifnot; ! TARGET_GLULX
	@gestalt gid arg val;
#Endif; ! TARGET_

return val;

];

[ Test val ;

#Ifdef TARGET_ZCODE;
	! Check we're in a 1.2 version interpreter
	val = HDR_SPECREVISION-->0;
	if (val < $0102) rfalse;
#Endif; ! TARGET_ZCODE

! Checking for @parchment support
if ( Gestalt($20, $1110, 0) == 0 ) rfalse;

! Check for raw eval() support
if ( Gestalt($20, $1110, 1) == 0 ) rfalse;
rtrue;

];

[ Parchment id arg val;

! @parchment wrapper
#Ifdef TARGET_ZCODE;
	@"EXT:31S" id arg -> val;
#Ifnot; ! TARGET_GLULX
	@"S3:4368" id arg val;
#Endif; ! TARGET_

return val;

];
-).

To decide whether javascript io enabled: (- (Test()) -).

To js (javascript code - some indexed text):
if javascript io enabled:
open Parchment channel;
say “[javascript code][run paragraph on]”;
close Parchment channel;
otherwise if standalone mode is false:
say “***[javascript code]***[line break]”.

To open Parchment channel: (- Parchment(1, 1); -).
To close Parchment channel: (- Parchment(1, 0); -).[/code]

This let me just then write something like:

js "activateOverlay('[current narrator]');";

…in an Inform phrase to interface with the Javascript layer.