Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Add a JavaScript library in Harlowe?

I want to use Underscore.js in a Harlowe based twine. What's the best way to do this? Weirdly, putting

document.write('<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"><\/script>');

at the beginning of the story javascript mostly works. Using document.write() in the story js at all, even just document.write(""), breaks `(link: "foo")[bar]` and probably other Harlowe things (no idea why). If I asynchronously load the javascript using anything like document.createElement("script") etc, Underscore doesn't load soon enough for me to use it in text that starts out being shown to the user.

Side note: including the character sequence `</script>` in the story javascript breaks things :) which is why the backslash is in it above.

Example I want to work (yes I know Harlowe and Math both have a random feature-- this is just a testcase):

story javascript:
window.foo = function(){return "more than " + (20 + _.random(1,7));};

default passage:
The value is (print: foo()) !!!!! (link: "Yay")[It worked].
Sign In or Register to comment.