util.input.execute

Client

Executes a registered console command as if it had been typed into the console


Syntax

local status = util.input.execute(
    name,
    args = {}
)

Fires every handler registered under name, the same way console input does.

  • Strings onlyargs values are converted with tostring internally, so pass strings where possible to match what a real console handler receives.
  • Not for binding — this only reaches handlers set up with util.input.register.
    Key and mouse binds registered through util.input.bind live in a separate registry entirely and won't fire from this call.

Parameters

TypeNameDescription
stringnameCommand name to execute
tableargsArray of arguments to pass through to the handler

Returns

TypeNameDescription
boolstatustrue if a handler for name exists and was invoked, false otherwise

Examples

Execute a command without arguments
util.input.register("respawn", function(args)
    core.engine.print("info", "Respawning player")
end)

util.input.execute("respawn")
Execute a command with arguments
util.input.register("teleport", function(args)
    core.engine.print("info", "Teleporting to", args[1], args[2], args[3])
end)

util.input.execute("teleport", {"10", "20", "30"})
Guard against a missing command before executing
if not util.input.execute("debug_dump") then
    core.engine.print("warn", "debug_dump is not registered")
end
Non-string arguments are coerced automatically
util.input.register("set_speed", function(args)
    core.engine.print("info", "New speed:", args[1])
end)

-- Numbers are converted to strings before the handler receives them
util.input.execute("set_speed", {15.5})

On this page