The general definition of a function in GML is something like this:

A function has an input and an output, and the output is related somehow to the input.

In GameMaker Studio 2 you use functions as part of the code structure to make things happen in your game and there are a great number of GML functions available to you, all of which are explained in the Language Reference section of the manual.

In GML a function has the form of a function name, followed by the input arguments between brackets and separated by commas (if the function has no input arguments then just brackets are used). Here is an outline of the structure of a function:

<function>(<arg0>, <arg1> ,... <arg15>);

Generally there are two types of functions - first, there is the huge collection of built-in functions which are used to control all aspects of your game, and, second, any scripts you define in your game can also be used as a function (but not always).

Some functions return values and can be used in expressions, while others simply execute commands, as illustrated in the following two examples:

instance_destroy();                              // Destroy the calling instance - this requires no arguments and returns nothing
dist = point_distance(x, y, mouse_x, mouse_y;    // Get the distance from the current instance position to the mouse position - takes four arguments and returns a real value

You should note that it is impossible to use a function by itself as the left-hand side of an assignment. For example, the following code would give you an error:

instance_nearest(x, y, obj).speed = 0;

The return value for the expression in that code example is a real number (the unique ID value for the nearest instance) and so it must be enclosed in brackets to be used in this way and properly address the instance required (see Addressing Variables In Other Instances for more information). The above code would be correctly written as:

(instance_nearest(x, y, obj)).speed = 0;
var inst = instance_nearest(x, y, obj);
inst.speed = 0;