JavaScript

How to Avoid JavaScript Scope Issues With Twine 2 (and SugarCube)

You’re using Twine 2 with the SugarCube story format for your interactive fiction story, but JavaScript is throwing curveballs your way. Functions that work like a charm elsewhere mysteriously trigger cryptic error messages. The culprit? JavaScript scope.

Let Your Functions Mingle

The Story JavaScript area, any JavaScript file in the compile path of a Twee notation project, or code written within SugarCube’s <<script>> tags operates in a “Private Scope.”

Imagine a private scope in JavaScript like a private room in a house. It’s a space where everything you put inside (your functions and variables) is only available to those who are inside the room. This privacy sounds great for security, but not so much when you want your code to mingle with other parts of your Twine story.

Continue Reading
Scroll to top