Howdy, Stranger!

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

Muliple startup java scripts in Twine 2

Hi, I am new to twine, and have not used Twine 1.

I read some forums, and watched some tutorials, and in Twine 1 it was possible to have multiple java startup scripts, because you could create a multiple passages with the "script" tag which would be loaded in alphabetical order.

In Twine 2 instead of this method there is instead an "Edit Story JavasSript" where the startup java script is called.

Is there still a way in Twine 2 to make it load multiple java script files on startup?

I would like to have my "init_inventory" and "init_stats" java script code in separate passages/files.

Thanks, anyone who can help.

Comments

  • ... in Twine 1 it was possible to have multiple java startup scripts, because you could create a multiple passages with the "script" tag which would be loaded in alphabetical order.
    A small but important clarification.

    While it is true that it is possible in Twine 1 to have more than one passage marked with a "script" tag, it is generally recommend not to do this if the Javascript in one passage referenced the Javascript within another. This is because there is no easy way for the Author to control the order that script tagged passages will be executed/loaded in Twine 1, that was left up to the story format to decide and the Author could not rely on it being in alphabetical order.

    You should state which story format you are using, as answers can be different for each one.

    I searched the forums and found two previous answers to a question like yours, this comment and this comment either of which may work for you.
  • edited October 2015
    greyelf wrote: »
    You should state which story format you are using, as answers can be different for each one.

    I searched the forums and found two previous answers to a question like yours, this comment and this comment either of which may work for you.

    Hi, thanks for the response.

    In regards to the story format, there really should not be a difference because the java script gets executed before the first passage of any story format. (From what I read anyway.)

    As to the forum search, I also found those comments, however both those "work arounds" imply I must load my java script manually from outside the Twine project at run-time. What I was really hoping for was a way to have multiple java script files stored in the Twine project itself.

    It's not the end of the world... just having a large java script file up front is a little unwieldy.

    I guess since nobody else has a way of doing this, it is not possible at this time.
  • In regards to the story format, there really should not be a difference because the java script gets executed before the first passage of any story format. (From what I read anyway.)
    Each story format embeds it's own unique set of third-party Javascript libraries and that fact can influence answers to Javascript related questions. Which is why I suggested you should always include which story format you are using when asking a question.

    I suggested the solutions I did because you used the word file in your original question, which implied that the Javascript was going to be stored in external js files. If you had used the word passsage instead then I would of given a different answer, and that would of been that it may be possible.

    Both Harlowe and SugarCube allow you to access the raw text stored within a passage, so it may be possible to use Javascript to append that text to the head element as the contents of a script element. I have not tried this myself.
Sign In or Register to comment.