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

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

  ## Alias

  * `debug.getconstant`

  ## Arguments

  <ParamField path={"target"} type={"function | number"} required>
    Lua function or stack level whose constants are inspected.
  </ParamField>

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

  ## Retours

  <ResponseField name={"constant"} type={"any | nil"}>
    Constant value at the requested index, or nil when that constant is a function or table.
  </ResponseField>

  ## Exemple

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