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

<div className="real-function-page">
  ```lua theme={null}
  setconstant(target: function | number, index: number, value: any)
  ```

  ## Alias

  * `debug.setconstant`

  ## Argumentos

  <ParamField path={"target"} type={"function | number"} required>
    Lua function or stack level whose constant is modified.
  </ParamField>

  <ParamField path={"index"} type={"number"} required>
    One-based constant index.
  </ParamField>

  <ParamField path={"value"} type={"any"} required>
    New value for the constant.
  </ParamField>

  ## Ejemplo

  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))
  ```
</div>
