Starlark Basics & Rules
MPLC runs Starlark, a deterministic dialect of Python designed for safe embedded scripting.
Program structure
Section titled “Program structure”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, helpersCOUNT = 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(), orregister()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 aregister()and call.set()with a replacement value. - Statements at top level:
ifandforstatements must appear inside functions (scan()or helpers), not at top level.
Data types
Section titled “Data types”| 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. |
MPLC handle types
Section titled “MPLC handle types”Calling type(x) returns "Point", "Group", "Register", or "Buffer" for MPLC handles.
Standard Starlark built-ins available
Section titled “Standard Starlark built-ins available”Common Starlark functions and operators work as expected:
- Operators:
+,-,*,/(float),//(int floor),%,==,!=,<,<=,>,>=,and,or,not,in,not in, ternarya 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].
Intentional omissions
Section titled “Intentional omissions”To keep scans bounded and deterministic, MPLC’s Starlark intentionally excludes:
whileloops — useforover bounded ranges or groups instead.- Recursion — functions cannot call themselves directly or indirectly.
sleep()or wait-for-event — return fromscan()and check again on the next scan; measure elapsed ticks withnow()ormplc:timers.class,try/except,import, file/network I/O — useload()for modules andregister()/ dicts for structured state.
Source & load limits
Section titled “Source & load limits”| 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.