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

# getconstant

> Returns one constant from a Lua function or stack level by one-based index. target must be a function or stack level number. Invalid stack levels raise "Level out of range". Non-function and non-number targets raise a type error expecting "function or number". C closures raise "Lua function expected". Indexes below 1 raise "Constant index starts at 1", and indexes past the available constants raise "Constant index out of range". Function and table constants are returned as nil. debug.getconstant is an alias.

Returns one constant from a Lua function or stack level by one-based index. target must be a function or stack level number. Invalid stack levels raise "Level out of range". Non-function and non-number targets raise a type error expecting "function or number". C closures raise "Lua function expected". Indexes below 1 raise "Constant index starts at 1", and indexes past the available constants raise "Constant index out of range". Function and table constants are returned as nil. debug.getconstant is an alias.

## Syntax

```lua theme={null}
getconstant(target: function | number, index: number): any | nil
```

## Aliases

* `debug.getconstant`

## Arguments

| Name     | Type                 | Required | Description                                                |
| -------- | -------------------- | -------- | ---------------------------------------------------------- |
| `target` | `function \| number` | Yes      | Lua function or stack level whose constants are inspected. |
| `index`  | `number`             | Yes      | One-based constant index.                                  |

## Returns

| Name       | Type         | Description                                                                              |
| ---------- | ------------ | ---------------------------------------------------------------------------------------- |
| `constant` | `any \| nil` | Constant value at the requested index, or nil when that constant is a function or table. |

## Example

Read a one-based Proto constant from a Lua closure.

```lua theme={null}
local function target()
    return "ready"
end

local value = getconstant(target, 1)

print(value)
print(debug.getconstant(target, 1))
```
