require
One script using another
Loads another script from your library and returns its exports. A module is an ordinary script, so it stays editable, runnable and previewable. It runs in the same context and sees the same globals and bridges. A module that throws while loading stops the run, and the error names the module and the line inside it.
Methods
require(name)AnyLoads another script from your library and returns what it exported. The module sets module.exports; names are matched case-insensitively against script titles. Requiring the same module twice gives the same object, so state is shared. Cycles and chains deeper than 8 are refused with a message naming the path.
- name String required
The other script's title, matched without regard to case or surrounding spaces.
returns Whatever the module assigned to module.exports.
Examples
A shared helper
// In a script titled "Helpers"
function greet(name) {
return "Hello, " + name;
}
module.exports = { greet: greet };
// In any other script
var helpers = require("Helpers");
Script.setWidget(new Widget({
child: Text(helpers.greet("world")),
}));