Skip to main content

Overview

@nodiscard marks a function whose return value callers should use. If you call the function and ignore the return value, GLuaLS reports discard-returns.

Syntax

---@nodiscard
---@nodiscard "Reason or alternative"

Usage

---@nodiscard
---@return string
function GetPlayerToken(ply)
    return ply:SteamID64()
end

-- This will trigger a warning:
GetPlayerToken(ply)  -- ❌ discard-returns: return value is unused

-- This is fine:
local token = GetPlayerToken(ply)  -- ✅

With a custom message

Add a string to explain why the return value matters:
---@nodiscard "Use the returned handle to cancel the timer"
---@return TimerHandle
function StartBackgroundTimer(callback)
    -- ...
end
The message appears in the diagnostic.

When to use

Use @nodiscard on functions where:
  • Ignoring the return value is usually a bug, such as getting a handle or a result you must check
  • Callers must manage work tied to the return value, such as cleanup or cancellation
Common candidates in GMod:
  • Functions returning an Entity that the caller is expected to configure
  • Functions returning a success boolean
  • Token or handle-returning functions