Skip to content
Lucent
Esc
↑↓navigate↵open
On this page

Writing scripts

Learn the basic structure of a script.

Script environment

Load the focused modules needed by the script:

  • lucent/api controls the game.
  • lucent/script handles lifecycle, inputs, options, logging, and other utilities.
  • lucent/schema validates and transforms data.
  • lucent/http sends HTTP requests with script cancellation and timeouts.
  • lucent/filesystem persists shared files in Documents/Lucent/data.
  • lucent/autozone controls automatic encounter-zone movement.
  • lucent/autorelogin controls 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.

Type preview
Open page

Last updated on September 26, 2026

Was this page helpful?