Get passage from Javascript

Hello, i've been using Squiffy for a few days and can see it help a project come to life.

Is there a way to get the text from a passage from JavaScript?

For example, imagine this squiffy passage

[[Passage]]
This is the text I want to get from JavaScript

And then have a little JavaScript to get this as a variable
e.g.
var text = squiffy.get.passage("Passage");

Its the squiffy call at the end I am looking for help on.

Thanks!


If it's a section (as in the example you quote):

[[Passage]]:
This is a section named "Passage".

then you can do:

    var text = squiffy.story.sections["Passage"].text;

If it's a passage in the current section, like this:

[Passage]:
This is a passage called "Passage".

then you can do:

    var text = squiffy.story.section.passages["Passage"].text;

If it's a passage but not in the current section, for example:

[[Section]]:
This is a section named "Section".

[Passage]:
And this is a passage named "Passage" inside the section named "Section".

then you would do:

    var text = squiffy.story.sections["Section"].passages["Passage"].text;

However, you should note that if that section/passage contains any text processor stuff (like {if or {Attribute}) those might not be processed. If you want to get the text as it would display, then you will need to run the text processor over it first. I believe this is:

    var text = squiffy.ui.processText(squiffy.story.sections["Passage"].text);

The text you get by this method won't be quite the same as what you entered in the Squiffy editor; because line breaks and section/passage links are converted to HTML when the game is compiled. But I think in most circumstances you won't need to worry about that.

Sorry if I got any of the names wrong; I'm on my phone here, so answering off the top of my head.


This is great, thank you very much.
Yes I meant section not passage so thank you for the comprehensive response.


This topic is now closed. Topics are closed after 180 days of inactivity.

Support

Forums