Skip to content

Starlark Basics & Rules

MPLC runs Starlark, a deterministic dialect of Python designed for safe embedded scripting.

Every main PLC program must define a top-level scan() function taking no parameters:

load("mplc:timers", "on_delay") # 1. load() statements must come first
SUPPLY = point("supply/item") # 2. Handles, constants, registers, helpers
COUNT = register("count", 0)
def scan(): # 3. Entry point called once per scheduled scan
COUNT.set(COUNT.get() + 1)
  • Top level runs once per load, not once per scan. Constructing point(), points(), hub(), or register() handles does not read the world.
  • Top-level values freeze once loading finishes. Attempting to mutate a top-level list or dict inside scan() fails; copy it or store mutable state in a register() and call .set() with a replacement value.
  • Statements at top level: if and for statements must appear inside functions (scan() or helpers), not at top level.
Type Examples Notes
bool True, False Capitalized True / False.
int 0, 42, 200_000, -1 Arbitrary-precision integers; use // for integer division (/ produces a float).
float 0.5, 3.14 IEEE 754 floating-point.
string "minecraft:coal", '#c:logs' UTF-8 strings; immutable.
list [1, 2, 3] Ordered, mutable within a scan (frozen if top-level or returned from register.get()).
tuple (1, 1, 0) Immutable sequence; used for (x, y, z) coordinates.
dict {"minecraft:coal": 16} Key-value mapping; returned by contents().
set set(["a", "b"]) Unordered unique elements.
None None Absent value; cannot be used as a register() default.

Calling type(x) returns "Point", "Group", "Register", or "Buffer" for MPLC handles.

Common Starlark functions and operators work as expected:

  • Operators: +, -, *, / (float), // (int floor), %, ==, !=, <, <=, >, >=, and, or, not, in, not in, ternary a if cond else b.
  • Built-ins: abs, all, any, bool, dict, dir, enumerate, float, getattr, hasattr, hash, int, len, list, max, min, range, repr, reversed, set, sorted, str, tuple, type, zip.
  • List/dict comprehensions: [x for x in items if x > 0].

To keep scans bounded and deterministic, MPLC’s Starlark intentionally excludes:

  • while loops — use for over bounded ranges or groups instead.
  • Recursion — functions cannot call themselves directly or indirectly.
  • sleep() or wait-for-event — return from scan() and check again on the next scan; measure elapsed ticks with now() or mplc:timers.
  • class, try/except, import, file/network I/O — use load() for modules and register() / dicts for structured state.
Limit Value
Max source file size 16,384 UTF-8 bytes per file
Top-level load step budget 7,700 steps across the main file and all loaded modules combined
Max installed modules per PLC 256 modules (names ≤ 64 characters)
Library entry names [a-z0-9_], up to 32 characters

Not an official Minecraft website. Not approved by or associated with Mojang or Microsoft.