Functions

This section explains what a function is in GameMaker: Studio

The general definition of a function is something like this: A function has an input and an output, and the output is related somehow to the input. In GameMaker: Studio you use functions as part of the program to make things happen in your game and there are a great number of GML (GameMaker Language) functions available to you, all of which are explained in the 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 of all, there is the huge collection of built-in functions which are used to control all aspects of your game, and, secondly, 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 and you should note that it is impossible to use a function as the left-hand side of an assignment. For example, you cannot write:

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


as the return value for the expression is a real number and so must be enclosed in brackets to be used in this way (see Addressing Variables In Other Instances for more information), so the above code should actually be written as:

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


Back: GML Overview
Next: Assignments
© Copyright YoYo Games Ltd. 2018 All Rights Reserved