> ## 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.

# setconstant

> Replaces one constant in a Lua function or stack level by one-based index. Invalid stack levels raise "Level out of range", non-Lua functions 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". debug.setconstant is an alias.

Replaces one constant in a Lua function or stack level by one-based index. Invalid stack levels raise "Level out of range", non-Lua functions 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". debug.setconstant is an alias.

## Syntax

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

## Aliases

* `debug.setconstant`

## Arguments

| Name     | Type                 | Required | Description                                             |
| -------- | -------------------- | -------- | ------------------------------------------------------- |
| `target` | `function \| number` | Yes      | Lua function or stack level whose constant is modified. |
| `index`  | `number`             | Yes      | One-based constant index.                               |
| `value`  | `any`                | Yes      | New value for the constant.                             |

## Example

Replace one Proto constant in a Lua closure or stack level.

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

print(getconstant(target, 1))

setconstant(target, 1, "after")
print(getconstant(target, 1))

debug.setconstant(target, 1, "done")
print(getconstant(target, 1))
```
