Skip to content


The programming language JavaScript is embedded in all modern web browsers and is a foundational part of how Twine works.

Knowledge of JavaScript is not required to create stories using Twine. However, understanding how JavaScript works and the expectations of how things are structured in the language can be helpful when using advanced functionality in SugarCube and when using Snowman.

Story JavaScript#

When using Twine, extra functionality can be added through the Story JavaScript screen. This is run before the Story is run and provides an opportunity to write specialized code or include external libraries and files. Some story formats, like SugarCube, provide the ability to translate between JavaScript and macro usage in Twine. Others, like Snowman, expect this to be used when creating more complex projects.


Based on the object provided by SugarCube of the same name, this cookbook suggests using or creating a window.setup global object when working with Story JavaScript in Twine for greater portability between story formats.

window.setup Example

window.setup = window.setup || {};