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:

GML Code Example

<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:

GML Code Example

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:

GML Code Example

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

No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here