Skip to content

JavaScript

Inkweaver’s scripting language is JavaScript. If you know JavaScript, you’re ready to start coding.

Inkweaver takes care of the hard parts, like following the screenplay and managing saves, so you can spend your time on what makes your story unique.

New to JavaScript? Don’t let that stop you. The patterns you’ll learn here are the same ones professional developers use every day.

This example keeps track of how much a character trusts the reader. Your screenplay marks the lines where trust changes, and the script updates the score.

import { getState, onLabel, updateState } from "@inkweaverdev/inkweaver-sdk";
/**
* Increases 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 whole block of dialogue,
* 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 workspace’s project.json:

{
"main": "index.js",
"version": "1.0.0"
}

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

The version field is required, and must be a semantic version.

Every script can use the Inkweaver SDK. To see everything it can do, start with the Inkweaver SDK reference.