Skip to main content

Dispatcher

The dispatcher handles parsing, validating, and evaluating commands.

Properties

Cmdr

This item is read only and cannot be modified. Read Only
Dispatcher.Cmdr: Cmdr | CmdrClient

A reference to Cmdr. This may either be the server or client version of Cmdr depending on where the code is running.

Registry

This item is read only and cannot be modified. Read Only
Dispatcher.Registry: Registry

Functions

EvaluateAndRun

Dispatcher:EvaluateAndRun(
textstring,
executorPlayer?,
options{
Dataany?,
IsHumanboolean?,
}?
) → string--

Command output or error message

Runs a command as the given player. Executor is optional when running on the client.

If options.Data is given, it will be available on the server with CommandContext.GetData

If options.IsHuman is true and this function is called on the client, then the text will be inserted into the window history.

Run

This item only works when running on the client. Client
Dispatcher:Run(...string...) → string

Invokes a command programmatically as the local player. Accepts a variable number of arguments, which are all joined with spaces before being run; the command should be the first argument. This function will raise an error if any validations occur, since it's only for hard-coded (or generated) commands.

GetHistory

This item only works when running on the client. Client
Dispatcher:GetHistory() → {string}

Returns an array of the user's command history. Most recent commands are inserted at the end of the array.

Show raw api
{
    "functions": [
        {
            "name": "Evaluate",
            "desc": "Takes in raw command information and generates a command out of it.",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "executor",
                    "desc": "",
                    "lua_type": "Player"
                },
                {
                    "name": "allowIncompleteArguments",
                    "desc": "when true, will ignore errors about arguments missing so we can parse live as the user types",
                    "lua_type": "boolean?"
                },
                {
                    "name": "data",
                    "desc": "is for special networked Data about the command gathered on the client, purely optional.",
                    "lua_type": "any?"
                }
            ],
            "returns": [
                {
                    "desc": "if unsuccessful, returns false and the error text",
                    "lua_type": "(command) | (false, string)"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 45,
                "path": "Cmdr/Shared/Dispatcher.lua"
            }
        },
        {
            "name": "EvaluateAndRun",
            "desc": "Runs a command as the given player. Executor is optional when running on the client.\n\nIf `options.Data` is given, it will be available on the server with CommandContext.GetData\n\nIf `options.IsHuman` is true and this function is called on the client, then the `text` will be inserted into the window history.",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "executor",
                    "desc": "",
                    "lua_type": "Player?"
                },
                {
                    "name": "options",
                    "desc": "",
                    "lua_type": "{\r\n\t\tData: any?,\r\n\t\tIsHuman: boolean?,\r\n\t}?\r\n"
                }
            ],
            "returns": [
                {
                    "desc": "Command output or error message",
                    "lua_type": "string"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 94,
                "path": "Cmdr/Shared/Dispatcher.lua"
            }
        },
        {
            "name": "Send",
            "desc": "Send text as the local user to remote server to be evaluated there.",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "data",
                    "desc": "is for special networked Data about the command gathered on the client, purely optional.",
                    "lua_type": "any?"
                }
            ],
            "returns": [
                {
                    "desc": "Command output or error message",
                    "lua_type": "string"
                }
            ],
            "function_type": "method",
            "realm": [
                "Client"
            ],
            "private": true,
            "source": {
                "line": 144,
                "path": "Cmdr/Shared/Dispatcher.lua"
            }
        },
        {
            "name": "Run",
            "desc": "Invokes a command programmatically as the local player.\nAccepts a variable number of arguments, which are all joined with spaces before being run; the command should be the first argument.\nThis function will raise an error if any validations occur, since it's only for hard-coded (or generated) commands.",
            "params": [
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "string..."
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "method",
            "realm": [
                "Client"
            ],
            "source": {
                "line": 164,
                "path": "Cmdr/Shared/Dispatcher.lua"
            }
        },
        {
            "name": "RunGuards",
            "desc": "Runs command-specific guard methods",
            "params": [
                {
                    "name": "commandContext",
                    "desc": "",
                    "lua_type": "CommandContext"
                },
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "ArgumentContext..."
                }
            ],
            "returns": [
                {
                    "desc": "nil for ok, string (errorText) for cancellation",
                    "lua_type": "nil | string"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 200,
                "path": "Cmdr/Shared/Dispatcher.lua"
            }
        },
        {
            "name": "RunHooks",
            "desc": "Runs hooks matching the specified HookName",
            "params": [
                {
                    "name": "hookName",
                    "desc": "",
                    "lua_type": "HookType"
                },
                {
                    "name": "commandContext",
                    "desc": "",
                    "lua_type": "CommandContext"
                },
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "ArgumentContext..."
                }
            ],
            "returns": [
                {
                    "desc": "nil for ok, string (errorText) for cancellation",
                    "lua_type": "nil | string"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 236,
                "path": "Cmdr/Shared/Dispatcher.lua"
            }
        },
        {
            "name": "PushHistory",
            "desc": "Inserts the string into the window history",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [],
            "function_type": "method",
            "realm": [
                "Client"
            ],
            "private": true,
            "source": {
                "line": 278,
                "path": "Cmdr/Shared/Dispatcher.lua"
            }
        },
        {
            "name": "GetHistory",
            "desc": "Returns an array of the user's command history. Most recent commands are inserted at the end of the array.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ string }\r\n"
                }
            ],
            "function_type": "method",
            "realm": [
                "Client"
            ],
            "source": {
                "line": 299,
                "path": "Cmdr/Shared/Dispatcher.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "Cmdr",
            "desc": "A reference to Cmdr. This may either be the server or client version of Cmdr depending on where the code is running.",
            "lua_type": "Cmdr | CmdrClient",
            "readonly": true,
            "source": {
                "line": 22,
                "path": "Cmdr/Shared/Dispatcher.lua"
            }
        },
        {
            "name": "Registry",
            "desc": "",
            "lua_type": "Registry",
            "readonly": true,
            "source": {
                "line": 28,
                "path": "Cmdr/Shared/Dispatcher.lua"
            }
        }
    ],
    "types": [],
    "name": "Dispatcher",
    "desc": "The dispatcher handles parsing, validating, and evaluating commands.",
    "source": {
        "line": 15,
        "path": "Cmdr/Shared/Dispatcher.lua"
    }
}