Scripting Overview#

Simple Byte Storage: Scripting is an optional addon, shipped as a separate jar built from the same repository. It requires Simple Byte Storage.

The addon bundles Rhino (a JavaScript engine for Java). Rhino is only inside the addon jar; the core mod never contains it.

Blocks#

Block Role
Logic Bus Runs one JavaScript script. Sees its six neighbouring inventories and the network. Has its own GUI (right-click) where its identifier is set.
Logic Terminal Opens the script editor for every Logic Bus connected to the same network.

Both are normal network nodes: they must connect to an online controller (touching or via cables).

Workflow#

  1. Place the Logic Terminal and one or more Logic Buses on the network.
  2. Put each Bus next to the inventory (chest, furnace, machine) it should control.
  3. (Optional) Right-click each Bus and give it an identifier (see Identifiers).
  4. Right-click the Terminal. Pick a Bus from the list on the left.
  5. Write the script in the editor, then press Save.
  6. Press Run. The status line and the log below the editor show what happens.

Buttons:

Button Action
Save Stores the script on the bus. Saving stops the bus, press Run to start it.
Run / Stop Starts or stops the script.
Reload Discards edits and reloads the script stored on the bus.
− / + Changes the run interval by 10 ticks.

The terminal must be within ~12 blocks of the player for actions to be accepted. If opsOnly is on and you aren't allowed, the terminal is read-only.

Identifiers#

Every Logic Bus can have an identifier (ID). A script always runs on one bus, but with an ID it can reach the inventories next to other buses of the same network, selected by name.

Where you set it: the Logic Bus GUI#

Right-click a Logic Bus to open its own GUI (the script editor is a different screen, the Logic Terminal). The ID belongs to that one bus:

Assigning IDs requires edit permission (see opsOnly in Administration).

In the Logic Terminal#

The Logic Terminal shows the same list of IDs on its right-hand side (for convenience while writing scripts). Clicking an ID selects the first bus with that ID. In the bus list on the left, a bus with an ID is shown by its ID (in colour), otherwise by its coordinates; hover a row to see both. IDs are not edited in the terminal.

Changing an ID does not stop the bus and doesn't need a re-save. The script sees the new value on its next run (busId is refreshed every run; side(…, id) looks buses up each call).

Execution model#

// 1. The top level runs ONCE when the bus starts (compile + init).
var chest = side("up");
var counter = 0;

// 2. tick() runs every <interval> ticks.
function tick() {
  counter++;
}

Status values#

Status Meaning
(empty) Never started
saved Script saved, bus stopped
running Active
stopped Stopped by the player
ERROR: … Stopped by an error (syntax error, runtime error, limit exceeded) with line number where available

Persistence#

Script text, identifier, enabled flag and interval are stored in the block entity's NBT. Script variables and the log are not persisted. After a world restart an enabled bus recompiles and continues.


Found a mistake? This page is generated from docs/wiki/Scripting-Overview.md in the mod repository.