Loading function...

Please make sure JavaScript is enabled. Otherwise you will be unable to see the function documentation.

Register a Command with the current script and set the callback function for it. If the command is already registered to the current script, the callback function will be updated to the one given. If the command already exists for any other reason then the command will not be set and a warning will be shown in the console, but it is not an error. If there is no current DSL script to register with, the command will exist until cleared manually with ClearCommand.

Function receives the arguments passed from the command line as strings. If a string given in the command line is quoted then it is passed as a single argument, for example /help arg1 "arg2 arg3" will only pass two strings to the function, arg1 and arg2 arg3. All non-quoted whitespace is removed. This extra processing can be skipped by requesting a Raw argument, meaning only one un-modified string can be passed to the function.

The optional Help text is used by the built-in help command by doing something like /help Command.

Arguments

Results

Versions

DSL4 An error is no longer raised when the command name is already registered, and the optional Help text argument was added.

Example

Make a command to give the player some money.

SetCommand("give_money", function(dollars)
	
	-- Convert dollars to a number, this will return nil if nothing was given or the string doesn't represent a number.
	dollars = tonumber(dollars)
	if dollars then
		PrintError("expected amount of dollars to give")
	else
		PlayerAddMoney(dollars * 100) -- convert from dollars to cents
	end
	
end)

Process a command line string as if it was typed into the console.

Arguments

Results

Versions

DSL5 An error is no longer raised if the command does not exist or an error occurs during parsing, and Ran will indicate success or failure instead.

Unregister a Command from the current script. Nothing will happen if the command is not registered with the script, and no error will be raised.

Arguments

Results

None.

Check if a Command exists. This does not check if it is associated with the current script, but only if it exists at all.

Arguments

Results