intfiction.org

The Interactive Fiction Community Forum
It is currently Wed Jun 19, 2013 1:54 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Thu Jan 26, 2012 1:11 pm 
Offline
User avatar

Joined: Wed Nov 30, 2011 2:43 am
Posts: 228
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?


Top
 Profile Send private message  
 
PostPosted: Thu Jan 26, 2012 2:22 pm 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 2127
I don't know of an example of this, although it's technically possible.


Top
 Profile Send private message  
 
PostPosted: Thu Jan 26, 2012 3:07 pm 
Offline

Joined: Tue Dec 25, 2007 10:06 am
Posts: 898
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.

_________________
Vorple UI libraryBeta testing siteBlog


Top
 Profile Send private message  
 
PostPosted: Thu Jan 26, 2012 3:29 pm 
Offline
User avatar

Joined: Wed Nov 30, 2011 2:43 am
Posts: 228
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...


Top
 Profile Send private message  
 
PostPosted: Thu Jan 26, 2012 5:24 pm 
Offline
User avatar

Joined: Wed Oct 14, 2009 4:02 am
Posts: 981
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.


Top
 Profile Send private message  
 
PostPosted: Thu Jan 26, 2012 6:36 pm 
Offline
User avatar

Joined: Wed Oct 14, 2009 4:02 am
Posts: 981
Okay I've pushed the code to a new branch: https://github.com/curiousdannii/parchm ... evalstream

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


Top
 Profile Send private message  
 
PostPosted: Fri Jan 27, 2012 5:26 am 
Offline
User avatar

Joined: Wed Nov 30, 2011 2:43 am
Posts: 228
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.

Code:
/*
 * 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
}


Top
 Profile Send private message  
 
PostPosted: Sat Jan 28, 2012 1:49 pm 
Offline

Joined: Tue Mar 30, 2010 9:30 pm
Posts: 191
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); -).


This let me just then write something like:

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


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

_________________
Aaron Reed - Creating Interactive Fiction with Inform 7 - Smarter Parser


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: Eleas 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