Im trying to create a cycling link inside a javascript section of a passage. But chapbook converts my straight quotation marks into curly ones, and the string is not interpreted as an insert but just as text.
[JavaScript]
let response=`Hello!`;
let line1 = `{cycling link, choices: ['Hi!', '`;
let line2 = response + `']}`;
let line = line1+line2;
write (line);
[continue]
The result in the browser:
{cycling link, choices: [‘Hi!’, ‘Hello!’]}
As you see it converts the straight quotations marks into curly ones. And there is no cycling link but just literal text.
If you try and generate the raw Chapbook code in JavaScript (as you just were), I don’t believe it renders in the proper order to allow that (JavaScript, then Chapbook). Plus, you get the quotes being altered to opening and closing styles and I’m not quite sure how to avoid that.
Thanks Hall!! I’ll try it! I’m writting the game achivements, and it would be easier for me to group all that data in json format and then parse it into an object in the “Story JavaScript” section. I have tried already and i see my object has global scope. In fact its part of a bigger object that includes tools for parsing text and other utilities. My idea is to keep the passage for text and nice inserts or simple javascript function calls. But i see this approach has it disadvantages. I have read somewhere that it can get messy to work with arrays “hybridly” in javascript and the var section. Should i abandon my original idea? Are there any more known troubles that you think worth mention?
The bug is bigger than i thought. It goes far beyond “{cycling link”, or “reveal link” or inserts in general, but whenever you use the command “write” and the string parameter includes quotation marks or apostrophes, you may get all sorts of weird results: from the convertion of quotations to program crash.
I wish I had more experience with Chapbook to answer that confidently.
I definitely like using custom {inserts} and [modifiers] to create an elegant looking story syntax and for presenting clean, readable passage code. I can hide a bunch of generated HTML and JavaScript that way. Make a header insert and just send it the text you want displayed, then you can generate the HTML however you want in JS, for example. I made a stat adjuster that is simply an insert with the name of the variable. It then puts the + and - buttons around it and handles the live updating. Food for thought.
I hadn’t used quotes in variables before so I appreciate you sharing your findings.
I don’t typically use the [JavaScript] modifier in passages for rendering text; I mostly use custom {inserts}. However, you can replace all instances of the " with the " character code. You can use ' for ' as well. This seems to work, though it may not be very desirable.
Just tried my old code turning it into an insert, but the straight to curly conversion remained. Then i tried your trick ' but, although the quotation marks were then rendered straight, the cycling link was still interpreted as plain text, not as a cycling link. The same goes for reveal link…
I never thought that you could generate proper Chapbook code in the [javascript] modifier with the write() function… as it’s already running the Chapbook code rendering part by rendering the modifier already. However, I am using a rendering process call within Chapbook’s engine that can re-render a code block allowing me the send it any string of code (or a passage for that matter), if memory serves me correctly. I’d imagine you could send it a {cycling link} insert as a full string and all would be well.
I’m not at my computer so I can share that one line of code later if you need it. However, you can do a console.log() of the Chapbook engine and any other objects it uses to see the guts of it all.
And of course, sometimes you have to make a work around too. For example, I made my own insert that captures any key press to continue to the next passage. However, I couldn’t find a function call that actually navigates to a passage (maybe you know of one?)… so I made a [[link]] that was hidden and used JavaScript to simulate a click on the <a> tag.
I believe SugarCube has the most robust support for customization. Snowman is the format to use if you want to make your own engine though, as it has all the basic commands built-in and purposefully accessible to JavaScript. Snowman is intended as a framework first and foremost.
However, this shows that the Chapbook code is actually being rendered out. I do wonder is this engine.render() is necessary or if the write() function will render out properly rendered Chapbook code, once the bug is fixed.
I see Chris has responded to your bug report and is on it. That’s fantastic!
And then I just call it with {> cycling link}. You can send it variables, of course, and just modify the insert as necessary. If you are unfamiliar with that process, let me know. Otherwise, this might get you back on track.