> ## Documentation Index
> Fetch the complete documentation index at: https://docs.selvut.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Lua Basics

> Lua notes for Selvut scripts.

Selvut scripts use Lua syntax: `local` variables, `function` callbacks, tables for objects and arrays, and `nil` for missing values.

```lua theme={null}
local name = "Selvut"
local ticks = 0
local enabled = true
local missing = nil
```

Use tables for API options:

```lua theme={null}
local message = Setting.text("Message", {
  description = "Message printed by the script.",
  default = "Hello"
})
```

Register callbacks with `Script.on`:

```lua theme={null}
Script.on("tick", function(event)
  ticks = ticks + 1
end)
```

Many game-state APIs return `nil` when the player or world is unavailable:

```lua theme={null}
local pos = Player.position()
if pos == nil then
  Chat.log("No player yet")
end
```

Lua array-style tables are one-based:

```lua theme={null}
local values = { "A", "B", "C" }
Chat.log(values[1])
Chat.log(Random.pick(values))
```
