Docs Quick code
Coming from Lua or RPG in a Box
What's the same as Lua, what's different, and a Bauxite translation table.
#From Lua
The same: if / then / elseif / else / end, while / do / end, numeric for (both ends
included), repeat / until (the condition sees the body's locals), break, local with block
scope, function (global, local function, anonymous, function t.f(), function t:m()),
closures with real upvalues, recursion, return, .., ~=, #, -- and --[[ ]]
comments, nil, and / or giving one of their values, obj:method(), // and ^, and
pcall / error / assert.
Different:
| Lua | Quick code |
|---|---|
Tables are also arrays, from 1: t[1] |
Lists are their own kind, from 0: list[0], [1, 2, 3] ({1, 2, 3} makes a list too); list[-1] is the last. |
for i, v in ipairs(t) / for k, v in pairs(t) |
for i, v in list do / for k, v in table do — no ipairs / pairs; for v in list gives the items. |
| Several return values | One return value; return a list and take it apart: local a, b = f() takes the list's items. |
string.upper(s), s:upper(), table.insert(t, x) |
Global functions and methods: upper(s) or s:upper(), push(l, x) or l:push(x). |
#t on a table with names is 0 |
#t is how many values it has. |
Only x = x + 1 |
Also +=, -=, *=, /=, %=, ..=; and continue. |
~= only; not |
!=, &&, ` |
.. errors on nil / booleans |
.. joins anything ("x" .. nil is "xnil"). |
t.x = nil |
Same: takes the value out. |
| Globals are plain variables | Globals are the game's variables (saved); functions you write at the top are shared by the script's Code nodes. |
coroutine |
Every piece of code can already wait(); for parallel work use run_async, every, after. |
require("module") loads a file |
require("Name") loads a library script — see Libraries. |
Metatables, ..., goto, string.format patterns |
Not there. Use format("{0} {1}", a, b). |
Trailing ; optional |
Same; and a line starting with # is a comment. |
#From RPG in a Box (Bauxite)
The shapes are close: if … then … end, while … do … end, for x in … do … end and
wait(seconds) all read the same; a trailing ; is fine.
| Bauxite | Quick code |
|---|---|
$count = 1; |
count = 1 (or local count = 1) |
global.property["x"] |
x (a game-wide variable) |
self, player, entity["door"] |
self, player, object("door") |
entity["door"].property["opened"] |
object("door").opened (its own value) |
set_entity_offset(entity, x, y, z, t) |
obj.move(x, y, z, t) / obj.move_to(…) |
for $i in range(1, 4) do (4 excluded) |
for i = 1, 3 do (3 included) |
display_message("…") |
a Say node, or popup("…"), or self.say("…") |
function name($a) … end |
function name(a) … end |