Skip to content

JavaScript

Inkweaver doesn’t have a scripting language. It has JavaScript. If you know JavaScript, you’re ready to start coding.

Inkweaver takes care of the hard parts, like screenplay flow, and save state management. Your scripts only need to focus on what makes your story unique.

If you’re new to JavaScript, don’t let that stop you. The patterns that Inkweaver will teach you are used by professional developers every day.

Below is a script that implements a manages the “trustworthiness”. The screenplay decides where this score is applied, and the scripting handles the logic.

import { getState, updateState, onLabel } from "@inkweaverdev/inkweaver-sdk";
/**
* Increments the reader's trust score.
*
* Screenplay Usage:
*
* SOPHIA
* You covered for me back there. I won't forget that.
* <trust-up>
*/
onLabel("trust-up", () => {
const currentTrust = getState().trust ?? 0;
updateState({ trust: currentTrust + 1 });
});
/**
* Skips a line (or a character's entire dialogue
* block) if the reader isn't trustworthy.
*
* Screenplay Usage:
*
* SOPHIA <if-trustworthy>
* Wait, there's something I should tell you...
*/
onLabel("if-trustworthy", () => {
const currentTrust = getState().trust;
const shouldShowLine = currentTrust > 5;
return shouldShowLine;
});

Inkweaver finds your scripts through the main field in your project.json:

{
"main": "index.js"
}

This is your entry point. As your project grows, you can split your logic across multiple files and import them here.

The Inkweaver SDK is automatically available in every script. To learn more about all the features available to you, see the Inkweaver SDK documentation.