Howdy, Stranger!

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

Using javascript to goto a new passage in Harlowe

edited December 2015 in Help! with 2.0
Hi there,

I'm working in Twine 2.0 with Harlowe.

I'm want to allow the player a certain amount of time in a passage, and if they don't move on out of it on their own, to redirect them to a new passage.

I'm guessing i want to call Harlowe's Engine.gotoPassage function - although i don't seem to be able to access the Engine

The following code produces the error:


so i'm guessing this might be something to do with scope. Or something - I don't know... Or possibly I'm going about this totally wrong.

Thanks in advance for any help...


  • Harlowe is implemented in a way that deliberately limits access to it's internal Modules via reducing their scope, and as far as I know Harlowe does not currently have a documented Javascript API for Authors to use.

    Although there are ways to increase the scope of Harlowe's Modules using hacks like the following:
    window._harlowe = {"Engine": Engine}
    ... I would strongly suggest not relying on them as any changes to/restructure of those internals could result in your story no longer working.
  • thanks greyelf - so am i right in thinking that this is impossible in Harlowe (without me pretty much writing enough code that i'd be starting to write my own engine anyway...) and to do something like this i'd need to be working in Snowman?
  • iamalexf wrote: »
    ... so am i right in thinking that this is impossible in Harlowe
    No, in fact it is quite simple if your willing to use a scoping hack to access an undocumented feature of Harlowe.
    I personally don't like supplying solutions that rely on undocumented features/effects because they can then become the accepted way to do something, and the history of software developing has many examples of where using them has come back to haunt the developers. Parsing the Windows version string to determine the series of an instance of Windows is one famous example.
    iamalexf wrote: »
    ... and to do something like this i'd need to be working in Snowman?
    SugarCube also has a documented Javscript API which supports programmaticly showing a passage.

    One potential User Experience issue with redirecting based on real time in a Text based medium is that people read at different speeds (for a number of different reasons).
    I know that I would be slightly annoyed if I was part way through reading an interesting piece of text only to have it disappear without any warning.
  • edited December 2015
    Thanks again greyelf - this is really helpful- i'm trying to avoid starting out with hacks - at least until i understand better how everything works in twine... so in the meantime i've got it working in snowman. (code below for anyone who's interested).

    (i totally get it about different reading speeds - i'm trying to make something which plays with transience and the frustration of things slipping from your grasp and with text as fluid rather than fixed - and which will also have a feeling of things running on regardless if you don't interact with it. i get that there's access issues with this - once i've got a prototype up and running i think i'll play with allowing people to vary the speed it runs at.)

    Thanks again.

    Here's how it works in Snowman:
        	// this delays for 30seconds before moving on to a passage called "doing nothing"
    			$this=$(this);"doing nothing");

    EDIT: this needs a bit more thinking through - as we need to clear the queue when we leave the passage so that it doesn't redirect itself - i suspect this will be done using the "hidepassage" event to clear the queue on the document every time we click through to something new... I'll update this post when i've figured it out in case anyone else ends up here with this question.

    EDIT 2: this bit of code in the Story Javascript should do it (although it'll also clear anything else that's queued up at the document level)
  • If you don't mind the player knowing how much time they have to take action, what might be helpful is a timer bar either animated by CSS or using the html5 <progress> tag to deplete in the amount of time that they have.
Sign In or Register to comment.