Scripting
Lua scripts
Add your own modules, commands and HUDs to Minecraft Bedrock with Lua scripts.
Lumen runs scripts written in Lua 5.4. A script can add:
- Modules that sit in the menu like any other. They have their own settings, take keybinds, show in the array list and save to your config.
- Chat commands, like
.hello. - Handlers that run every tick, every frame, on chat messages, on hits and key presses, and when players join or leave, you die, the server shows a title and more.
Scripts also get timers and storage that is kept between sessions.
Every .lua file in the Scripts folder loads when the game starts, each one in its own sandbox.
The Scripts folder
Type this in chat to open it:
.lua folder
It lives at:
%LOCALAPPDATA%\Lumen\Client\Scripts
The first time Lumen starts, the folder holds example.lua, a small HUD that shows your speed and the nearest player, plus a .hello command. Read it, change it, or delete it.
Your first script
Make a file called hi.lua in the Scripts folder:
print("hi.lua loaded")
lumen.command("hi", "Says hi back.", function(args)
print("Hi " .. (args[1] or "there") .. "!")
end)
Then, in game:
.lua reload
.hi Steve
print writes to your own chat only; nobody else sees it.
Managing scripts
| Command | What it does |
|---|---|
.lua list | Every script, whether it loaded, and the error when it didn’t |
.lua reload | Reloads every script. Run it after you change one |
.lua load <name> | Loads or reloads one script, for example .lua load hi |
.lua unload <name> | Unloads one script and turns its modules off |
.lua folder | Opens the Scripts folder |
.lua run <code> | Runs one line of Lua and prints what it returned |
.lua watch <on/off> | Loads a script again whenever you save its file. .lua watch alone says whether it is on |
.script and .scripts work in place of .lua.
.lua run is handy for trying the API out:
.lua run player.health()
.lua run #world.players()
.lua run client.server()
Reloading as you save
.lua watch on
With this on, Lumen looks at the Scripts folder about once a second and loads a script again when its file changes. New files are picked up too. The choice is remembered.
A saved file that does not compile is not loaded: chat and a notification show the error with its line, and the version that was running keeps running.
When a script breaks
- If a script has a syntax error or fails while loading,
.lua listshows the error, and the other scripts load normally. - If a handler fails while running, the error is printed to chat as one line: the script, what was running, the file and line, and what went wrong. The full stack trace goes to the log.
- A module whose handler fails turns itself off. An error that keeps coming from the same place is printed at most once every five seconds, and a script that makes 10 errors within 10 seconds is stopped.
.lua listshows why. Fix the file and run.lua load <name>or.lua reload.
Next
- Script modules covers making a module with settings.
- Events and commands lists every event.
- API reference lists every function a script can call.
- Examples has complete scripts to copy.