How to <<include>> from inside javascript?

(Sugarcube 2.35)

Hey I was just wondering how to call an <<include>> from within javascript?

I’ve tried“passageName”); but that seems to be the equivalent of a <<goto>> and I really want to stay within the current passage.

Thanks so much!

Any answer is going to depend on exactly what you’re doing. Details matter.

While you can fudge calls to macros from JavaScript, this is one of the cases where doing so is unlikely to do you much good—unless you only want side-effects, which I’m assuming is not the case.

In general, you’re probably going to want to use the <jQuery>.wiki() method. Exactly what you’ll need to do depends on what you’re doing and where.

As one example. If you’re running some code within a <<script>> macro and want to include another passage as part of your code:

    /* other code… */

    $(output).wiki(Story.get('your passage name').processText());

    /* more code… */

That will output the passage, “your passage name”, within the currently rendering passage at the <<script>> call site, just as though you’d used <<include>> instead.

1 Like

Haha well even with the lack of detail, it turns out you guessed correctly!

I was trying to include a passage to use its nice sugarcube code:

:: quest item [nobr]
	<<set _qItem to $quest.types.random()>>

	<<set _qItemMessageID to "#item-message">> 
	<<set _qItemMessageRemove to "animate__backOutUp">>
	<<append "#passages">>
		<div id="item-message" class="animate__animated animate__backInDown" onclick="$.wiki('<<addclass _qItemMessageID _qItemMessageRemove>>')">				
			<div style= "margin: 5%">
				//<<=$>> <<=_qItem.bit.random()>> of <<=_qItem.cond.random()>>!//
				<div> <img @src="_qItem.img"> </div>

				_qItem.value points!

It really just creates a clickable div, some text and picture etc. but I’m not sure how to do that inside javascript.

Your code worked perfectly, thankyou so much!!! Definitely gonna use that from now on!