Writing scripts
Learn the basic structure of a script.
Script environment
Load the focused modules needed by the script:
lucent/apicontrols the game.lucent/scripthandles lifecycle, inputs, options, logging, and other utilities.lucent/schemavalidates and transforms data.lucent/httpsends HTTP requests with script cancellation and timeouts.lucent/filesystempersists shared files inDocuments/Lucent/data.lucent/autozonecontrols automatic encounter-zone movement.lucent/autorelogincontrols automatic login recovery.
const api = require("lucent/api");
const script = require("lucent/script");
See the scripting module reference for every module.
Scripts can also use the smaller effect module.
Create the script
Every script starts with a generator function:
module.exports = function* run() {
// Script body
};
Yield every action
Each action is a generator. Call it with yield* to run it and receive its
result before the script continues.
const api = require("lucent/api");
const script = require("lucent/script");
module.exports = function* run() {
yield* script.options.update({ roomPolicy: { kind: "random-private" } });
yield* api.player.joinMap("battleon");
const me = yield* api.player.get();
if (me !== null) {
yield* script.log(`Logged in as ${me.username}`);
}
};
Use the scripting reference to see what your scripts can do. When several scripts share code, put them in a script package.