How can I get the unprocessed text of a passage and store it in a variable?
Use-case: I have a function on my story’s JS setup object that returns an array of passage titles. I’d like to be able to select one of those array elements (a string holding a passage’s title) returned by the function and pass it into another JS function that would return the raw, unprocessed text of that passage.
Ultimately, I’d like to have a JS function that can be overloaded. The default would return the unprocessed text of the current story passage. But if passed a string, the function would – upon verifying that a passage exists matching that string title – return that passage’s raw text.
Yes, and that works fine as long as I manually assign a string literal, but I can’t seem to get it working when I try passing Story.get() a variable holding the desired passage title.
So if you left out those, you should still get the text of the passage, but when you print it out it would be processed instead of raw.
Dunno if that matches what you’re seeing…
Instead of nowiki tags with <<print>> you could also console.log() the text for debugging purposes (it’d show up in the browser’s JavaScript console instead of on the page).
<<set _current to passage()>>
The current passage is <<= _current>><br><br>
<<set _text to setup.getPassageText(_current)>>
<<print _text>>
This freezes the story when I try to run it in the browser. But if I remove the <<print _text>> line, it doesn’t lock up the browser when I run it.
If I replace the third line as shown below, the code runs fine and returns the text size in bytes as 3168, so I know that <<set _text to setup.getPassageText(_current)>> works.
The current passage is <<= _current>><br><br>
<<set _text to setup.getPassageText(_current)>>
The length of the returned text is <<= _text.length>>
I can’t figure out why <<print _text>> causes the browser to hang.
<<set _current to passage()>>
The current passage is <<= _current>><br><br>
<<set _text to setup.getPassageText(_current)>>
The length of the returned text is <<= _text.length>>
<<print _text>>
Oh. Yeah, doing that on the current passage is an infinite loop if it’s wiki-processing the text: as part of displaying the passage, it will print the passage again, which (when wiki-processed) will print the passage again, which will print the passage again…
You could then hide the contents of the <span> with CSS.
This will run all the code in the passage, including all variable changes and anything else that might alter the game state, which you probably don’t want to happen. It will also cause the game to hang if you run it on the current passage for the same reasons Josh explained.
Dang. I was wondering that from the doc text (“created from applying nobr tag and image passage processing to its raw text.”) but didn’t have time to test…