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

# ScriptData & ScriptVariables — Level Script Attachments Reference

> API reference for ScriptData and ScriptVariables in RollingQuest Lua scripting. Understand how scripts and their variables work on level elements.

## ScriptData

The `ScriptData` class represents a Lua script attached to a level element (level, block, side, item, enemy, ball, or decoration). Each script has a name and editable source code. Scripts are created and managed in the level editor.

## Properties

| Property     | Type     | Read/Write   | Description                          |
| ------------ | -------- | ------------ | ------------------------------------ |
| `name`       | `string` | ✅ Read       | Unique name identifying this script. |
| `sourceCode` | `string` | ❌ Read/Write | The Lua source code of the script.   |

## Usage Example

Read an existing script's info:

```lua theme={null}
function OnStart()
    -- Check if a script exists and read its properties
    Logger.info("Level has " .. Level.scriptsCount .. " scripts")
end
```

***

## ScriptVariables

The `ScriptVariables` class provides a key-value store for passing variables to scripts attached to level elements. Each element (block, side, item, etc.) can have its own `scriptVars` that are accessible within its attached script.

Variables are set at design time via the level editor.

## Indexer

Get or set variables by name:

```lua theme={null}
-- Set a variable (in the editor)
vars["spawnRate"] = 2.5
vars["enemyType"] = "goblin"
vars["isEnabled"] = true

-- Get a variable
local rate = vars["spawnRate"]
local type = vars["enemyType"]
```

## Usage Example

Read script variables from within a script:

```lua theme={null}
-- Inside a block's attached script
function OnStart()
    local speed = self.scriptVars["moveSpeed"]
    local dir = self.scriptVars["moveDirection"]
    local pause = self.scriptVars["pauseTime"]

    Logger.info("Block configured: speed=" .. speed .. " dir=" .. dir .. " pause=" .. pause)
end
```
