FANDOM


A parameter in scripting is a piece of information that is supplied when a function (or command) is invoked. This information can affect what exactly the function does. For example, a function that sends a message to all players would need to be told what message to send; the message is passed as a parameter.

Syntactically, parameters are a comma-separated list enclosed in parentheses immediately following a function name. When a function is called, the parameters can be explicit values or variables or even the return value of another function call (which then has its own parameter list, leading to nested parentheses).

    // The parameters to the function MyFunction are the numbers 1 and 5.0.
    MyFunction(1, 5.0);

When a function is defined (or declared), each parameter in the list consists of a type specifier followed by a name for that parameter.

// The parameters to the function MyFunction are
// an integer called nCount and a float called fSeconds.
MyFunction(int nCount, float fSeconds);

The type specifier restricts what kinds of information can be passed in that parameter, while the name is how the information will be referenced inside the function.

Some parameters are optional. An optional parameter is indicated in a function definition (and declaration) by appending an equals sign and a default value to the parameter name.

// A declaration where the second parameter is optional.
MyFunction(int nCount, float fSeconds=0.0);

When an optional parameter is omitted during a function call, the result is the same as if the default value was passed as the parameter. To avoid confusion, optional parameters must be at the end of the parameter list; there cannot be an optional parameter followed by a required parameter.

See also Edit