Linking back and forth between Twine and Inform 7

Dear Friends,

I am in need of some assistance. For my current project, I am attempting to create a narrative in which the interactor navigates through the story starting with the hyperlink functionality of Twine, and linking from there, also play in Inform. Thus, as the story progresses, the interactor switches back and forth between the two programs.

Initially, the plan was for Twine part of the game be playable in HTML, so linking to a released Inform project is simple enough…I believe. The real tricky part is linking to websites from Inform.

Please, if anybody may be of assistance, I ask for aid.

Cordially,

a. maus

The poster is a student of mine— I think the biggest technical issue here is how to make a Parchment-targeted Inform 7 project display a hyperlink to an external webpage. If you include actual HTML I believe the engine will convert it to < etc. symbols. Anyone know if there is a way around this?

Could you surgically insert a little javascript to change the symbols back into entities before “printing” them?

–Erik

I’m working on a more robust solution, but in the meanwile I hacked together a little script that turns {http://example.com Link name} into a hypertext link.

Edit the main HTML file (if you use the release with an interpreter option it’s play.html, otherwise index.html). Add the following script somewhere appropriate, just before the tag at the end is a good place:

<script> $( document ).bind( 'TextOutput', function( data ) { $( '#content' ).html( $( '#content' ).html().replace( /{(.*?)([\< ].*?)}/g, '<a href="$1" target="_blank">$2</a>' ) ); } ); </script>
This will open the links in a new window. If you want to open the links in the same window just remove the target="_blank" part from the above.

You must also remove the word defer from the script tags that load the libraries at the start of the file:

[code]

[/code]

(these say lib/ instead of interpreter/ if you use the stand-alone Parchment installation.)

This works only in the latest version of Parchment. If you’re using the one built into Inform, you have to update the Parchment library files and the jQuery library. Download these files: parchment.min.js, zmachine.min.js and jquery.min.js and replace the old ones in the interpreter directory.

Now you can add hyperlinks in Inform like this:

Test is a room. "Visit {http://intfiction.org/forum Intfiction.org forums} and {http://ifdb.tads.org IFDB}!"

Remember that this is just a very quick and dirty hack and it’s not supposed to be a general solution. Also, because it runs the whole story text through the regex every time it might slow down the interpreter if the transcript is very long, but I suspect it would become a problem only after an hour of play or so. I haven’t tested this with Internet Explorer but I don’t see a reason why it wouldn’t work (although you never know).

Juhana,

Thanks a lot. It works, but there’s definitely some copying and pasting that needs to be done beforehand, since we needed to keep a copy of the modified files so it wouldn’t get overridden by recompiling.

Cordially,

a. maus

You might also consider some of these solutions mentioned in these threads if you were not already aware of them.

https://intfiction.org/t/passing-variables-from-parchment-i7-to-javascript-and-back/1326/1

https://intfiction.org/t/parchment-experimental-extensions/1425/1

Paul.