Game Maker Language
Encyclopedia
Game Maker Language is a scripting language
developed for use with a computer game creation application
called Game Maker
. It was originally created by Mark Overmars
to supplement the drag-and-drop action system used in Game Maker. However, in the latest versions, all the drag-and-drop actions translate to GML rather than being separate from it.
GML is heavily integrated with the Game Maker environment. Usually, elements such as sprites and sounds are all organized within the Game Maker IDE (though they can also be loaded from external files). Game Maker's architecture is designed to handle such things as event detection, level design, and object configuration without the need to code them manually, minimizing code verbosity with intuitive interface features.
-based languages in its use of code blocks, function calls, variable assignments, operator syntax, and so on.
GML makes a difference between statements and expressions. For example
GML also allows C-style compound assignment operators. For example, the code
is the same as
The same function applies to the operators
Game Maker does not allow ternary operators(?:
syntax). Semicolons can be used to separate logical lines, but Game Maker does not enforce this.
Also Game Maker does not allow ++ and -- instead of +=1 and -=1.
API
.
GM also has built-in functions for calling external DLLs
. So, any feature not natively provided through Game Maker can be added using DLLs, making Game Maker a more sophisticated programming environment.
GM has many built in variables
and constants. Each instance
in the game has a set of built-in local variables such as "x" and "y". There are also some built-in global variables such as "score" which exist independent of individual instances.
User-defined variables can be either local or global. Local variables are the default; they are primarily used by the instance to which they are assigned. In order for another instance to use them, they must use the appropriate prefix, such as "(100001)." or "ball.". Global variables use a "global." prefix for all instances. In certain cases this prefix may be dispensed with: either if the variable has been initialized with "var" or "globalvar" statements, or if it is a built-in global variable.
Arrays may also be declared in GML and may be 1 or 2 dimensional. Arrays may contain a mix of strings and real values, but not arrays themselves. Arrays may not be passed to a function and may not be returned from a function in GML. GM also has built in limits on index sizes. Indexes may not be bigger than 32,000 and any single array may not contain more than total of 1,000,000 values.
GML also features functions used to create and edit six simple data structures. These functions are only available to users who have the Standard version of Game Maker. The data structures available are Stacks, Queues, Lists, Maps, Priority Queues, and Grids.
Because GML has no boolean values, statements that require boolean values, such as "if" will evaluate any value larger than 0.5 as true, and 0.5 or any smaller value as false. The constants "true" and "false" may be used in place of 1 and 0 in GML.
By default, a variable is local to an instance but not local to the script in which it is used. To make a variable accessible for all instances, it can either be accessed through the global namespace (
Variables that are local to an instance can be accessed outside of that instances actions by prefixing the variable name with an instance identifier (
The current instance namespace can be changed using the "with" construct. For example, the following piece of code, placed in a collision event, could be used to destroy the other instance involved. In generating a collision event, Game Maker automatically creates the variable "other" as a reference to the other object involved.
Note that when a variable is declared local to a particular script, it loses its association with the instance that called the script and becomes instance-independent. For example, the following code would work correctly even though the variable
A common gravity statement is one such as this.
For storing and manipulating larger amounts of data more efficiently, Game Maker has some built in data structures, such as stack
s, queues, lists, maps, priority queue
s and grids. These structures are created, modified, and destroyed through built-in functions which take a numerical value identifying the structure. There are also functions for sorting these structures, respective to each structure type. This can be particularly beneficial for speed optimization since the pre-compiled functions avoid the need to cycle through many loops of interpreted code. Memory for these structures is allocated and freed automatically by the implementation.
When creating resources or instances at runtime, its unique ID is returned and may then be passed to other variables and functions.
Another example that would display the same text in the game window instead. Note that by default, Game Maker redraws the background continuously, so using the default setting, this code would need to be attached to the draw event for drawing to work properly.
Here is a piece of code from a game using GML:
GML supports many variations in syntax. As a demonstration, the previous example could also be written like this:
Here is an example of basic keyboard-controller movement. The motion_set function takes two arguments: direction (degrees) and speed (pixels per step). Calling this function will assign an instance with a "speed" and "direction" (both built-in local variables), which Game Maker uses to update the instance's position automatically each step (an instance's position can also be modified directly using the built-in local "x" and "y" variables).
Here is an example of a more complex script from a platform game. Using this, the player can walk over hills and bumpy terrain.
Here is a piece of code that draws a simple 3D floor (the function
Manual
The manual that accompanies Game Maker is a document that has information on all the built-in functions and variables available in Game Maker, with the exception of action functions (the direct GML equivalents to drag-and-drop actions), and deprecated
variables and functions left in for backward compatibility, such as image_scale, which has been succeeded by image_xscale and image_yscale.
A notable example of a deprecated variable is image_single, which when changed to a sprite's subimage, will set image_speed to zero automatically, as well as setting image_index to the value image_single is set to.
Criticism
Common criticism towards Game Maker is its odd typing system, where variables can only be strings or real numbers, yet also be indexed like arrays. There is no way to make a variable hold an array, the name of the array implicitly accesses the zeroth element. As such, there is no way to pass an array as a script argument, except by passing a string holding the name of the array, which is then used to access the array itself. The other data structures are not very well integrated into the language, requiring a type unsafe index handle to the data structure, and requiring explicit deallocation (which has the potential for memory leaks). As well, they are only available to registered users.
The loose syntax of GML makes it easier to program in to an extent, but has the potential to cause very hard to read source code. The following is an example of what is possible:
Although not directly a part of the language, another common source of criticism is Game Maker's creation of .exe files that consist of a runner and the textual GML source, waiting until the end user runs the game to parse into an Abstract Syntax Tree
. This facilitates decompiling, and causes much slower start up times than necessary.
Scripting language
A scripting language, script language, or extension language is a programming language that allows control of one or more applications. "Scripts" are distinct from the core code of the application, as they are usually written in a different language and are often created or at least modified by the...
developed for use with a computer game creation application
Application software
Application software, also known as an application or an "app", is computer software designed to help the user to perform specific tasks. Examples include enterprise software, accounting software, office suites, graphics software and media players. Many application programs deal principally with...
called Game Maker
Game Maker
GameMaker is a Windows and Mac IDE originally developed by Mark Overmars in the Delphi programming language. It is currently developed and published by YoYo Games, a software company in which Overmars is involved...
. It was originally created by Mark Overmars
Mark Overmars
Markus Hendrik Overmars is a Dutch computer scientist and teacher of game programming known for his game development application Game Maker. Game Maker lets people create computer games using a drag-and-drop interface. He is the head of the Center for Geometry, Imaging, and Virtual Environments...
to supplement the drag-and-drop action system used in Game Maker. However, in the latest versions, all the drag-and-drop actions translate to GML rather than being separate from it.
GML is heavily integrated with the Game Maker environment. Usually, elements such as sprites and sounds are all organized within the Game Maker IDE (though they can also be loaded from external files). Game Maker's architecture is designed to handle such things as event detection, level design, and object configuration without the need to code them manually, minimizing code verbosity with intuitive interface features.
Libraries
In Game Maker, a set of drag-and-drop actions is called a library. In the Game Maker interface, these libraries are displayed as tabs containing icons called actions. Each action is a GML script or function that users can use in their games. Game Maker comes with a default set of libraries that contain the common actions used by most games; it is also possible to create libraries using the Library builder provided separately from Game Maker. There are many libraries that a Game Maker user may download to avoid using GML to achieve certain tasks. For example: If a user wants to make a simple 3D game but has no experience with GML, they can download a 3D Library.GML syntax and semantics
GML is structurally similar to CC (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
-based languages in its use of code blocks, function calls, variable assignments, operator syntax, and so on.
GML makes a difference between statements and expressions. For example
g < 1;
is not a valid statement and GM will return an error. Also, variable assignment is always a statement in GM, and cannot be used in an expression.GML also allows C-style compound assignment operators. For example, the code
is the same as
The same function applies to the operators
-=
, *=
, and /=
.Game Maker does not allow ternary operators(?:
?:
In computer programming, ?: is a ternary operator that is part of the syntax for a basic conditional expression in several programming languages...
syntax). Semicolons can be used to separate logical lines, but Game Maker does not enforce this.
Also Game Maker does not allow ++ and -- instead of +=1 and -=1.
Functions
Game Maker has a large library of built-in functions available for basic functionality. The programmer can also create scripts which are called in the same way functions are. The drawing functions in GML make use of the Direct3DDirect3D
Direct3D is part of Microsoft's DirectX application programming interface . Direct3D is available for Microsoft Windows operating systems , and for other platforms through the open source software Wine. It is the base for the graphics API on the Xbox and Xbox 360 console systems...
API
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...
.
GM also has built-in functions for calling external DLLs
Dynamic-link library
Dynamic-link library , or DLL, is Microsoft's implementation of the shared library concept in the Microsoft Windows and OS/2 operating systems...
. So, any feature not natively provided through Game Maker can be added using DLLs, making Game Maker a more sophisticated programming environment.
Variables
Normally, GML does not require that variables be declared as with many other scripting languages. A variable is created whenever a programmer first assign a value to it, as withfoo = "bar";
.GM has many built in variables
Variable (programming)
In computer programming, a variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents...
and constants. Each instance
Instance (computer science)
In object-oriented programming an instance is an occurrence or a copy of an object, whether currently executing or not. Instances of a class share the same set of attributes, yet will typically differ in what those attributes contain....
in the game has a set of built-in local variables such as "x" and "y". There are also some built-in global variables such as "score" which exist independent of individual instances.
User-defined variables can be either local or global. Local variables are the default; they are primarily used by the instance to which they are assigned. In order for another instance to use them, they must use the appropriate prefix, such as "(100001)." or "ball.". Global variables use a "global." prefix for all instances. In certain cases this prefix may be dispensed with: either if the variable has been initialized with "var" or "globalvar" statements, or if it is a built-in global variable.
Arrays may also be declared in GML and may be 1 or 2 dimensional. Arrays may contain a mix of strings and real values, but not arrays themselves. Arrays may not be passed to a function and may not be returned from a function in GML. GM also has built in limits on index sizes. Indexes may not be bigger than 32,000 and any single array may not contain more than total of 1,000,000 values.
GML also features functions used to create and edit six simple data structures. These functions are only available to users who have the Standard version of Game Maker. The data structures available are Stacks, Queues, Lists, Maps, Priority Queues, and Grids.
Types
For the sake of simplicity GML only has two variable types. Every variable may hold each type of data without any type declarations.- Strings are sets of ASCII characters that may be of very large lengths. However, because GM prefixes string sizes to the strings as a 4-byte integer, strings may not be longer than 4,294,967,296 characters. If a string exceeds this limit, 4,294,967,296 characters are cut from the beginning until the string is under the limit. However, most situations will use far shorter strings, so this limitation is rarely encountered.
- Real values are signed floating point numbers. Since version 6.1, GM has also allowed hexadecimal representation of real values in code (preceded by "$"). In version 6 real value handling had a bug which limited real value accuracy to be smaller than intended (which caused inaccurate results when calculating with large real values). The issue still exists in GM7, but it has been mitigated with greater precision.
Because GML has no boolean values, statements that require boolean values, such as "if" will evaluate any value larger than 0.5 as true, and 0.5 or any smaller value as false. The constants "true" and "false" may be used in place of 1 and 0 in GML.
Scope
In GML, there are two types of variable locality: locality to an "instance", and locality to a "script" (or any other piece of code that has its own container). Being local to an instance means that a variable is tied to that particular instance and can be called only with a prefix identifying the instance; being local to a script means that a variable can only be referenced within that script (and expires when the script finishes processing), since scripts do not have identifiers that are accessible to the user. When the term "local" is used without further specification, it usually refers to instance locality.By default, a variable is local to an instance but not local to the script in which it is used. To make a variable accessible for all instances, it can either be accessed through the global namespace (
global.foo = bar;
) or declared explicitly in the form globalvar foo, bar;
. With the former route, the variable must always be referenced with the global.
prefix; the globalvar
declaration allows a global variable to be accessed without the prefix. To make a variable local to the script in which it is used, the keyword var
is used, as in var foo, bar;
.Variables that are local to an instance can be accessed outside of that instances actions by prefixing the variable name with an instance identifier (
instanceReference.varname
). If multiple scripts are on the processing stack at the same time, there is no way to access script-local variables in one script from another, unless the variable is passed on to the other script as an argument.The current instance namespace can be changed using the "with" construct. For example, the following piece of code, placed in a collision event, could be used to destroy the other instance involved. In generating a collision event, Game Maker automatically creates the variable "other" as a reference to the other object involved.
Note that when a variable is declared local to a particular script, it loses its association with the instance that called the script and becomes instance-independent. For example, the following code would work correctly even though the variable
foo
is not defined for someOtherInstance
.A common gravity statement is one such as this.
Memory Management
GML automatically allocates and frees memory for variables, and variables local to a block or script are automatically destroyed when they go out of scope or when the script terminates.For storing and manipulating larger amounts of data more efficiently, Game Maker has some built in data structures, such as stack
Stack (data structure)
In computer science, a stack is a last in, first out abstract data type and linear data structure. A stack can have any abstract data type as an element, but is characterized by only three fundamental operations: push, pop and stack top. The push operation adds a new item to the top of the stack,...
s, queues, lists, maps, priority queue
Priority queue
A priority queue is an abstract data type in computer programming.It is exactly like a regular queue or stack data structure, but additionally, each element is associated with a "priority"....
s and grids. These structures are created, modified, and destroyed through built-in functions which take a numerical value identifying the structure. There are also functions for sorting these structures, respective to each structure type. This can be particularly beneficial for speed optimization since the pre-compiled functions avoid the need to cycle through many loops of interpreted code. Memory for these structures is allocated and freed automatically by the implementation.
Instances and resources
Game Maker does not support pointers to reference locations in memory. Thus, each resource and instance in Game Maker has a unique ID number, which is used to reference that particular resource or instance. This ID number can be used by scripts and functions to reference a particular instance or resource. Upon creation of a resource in GM the name of the resource is defined as a constant which references that resource (for objects the first instance is referenced). The ID of a particular instance of an object can be found using the variable "id".When creating resources or instances at runtime, its unique ID is returned and may then be passed to other variables and functions.
Code examples
Here is a simple piece of code that would display "Hello World!" in a popup message box.Another example that would display the same text in the game window instead. Note that by default, Game Maker redraws the background continuously, so using the default setting, this code would need to be attached to the draw event for drawing to work properly.
Here is a piece of code from a game using GML:
GML supports many variations in syntax. As a demonstration, the previous example could also be written like this:
Here is an example of basic keyboard-controller movement. The motion_set function takes two arguments: direction (degrees) and speed (pixels per step). Calling this function will assign an instance with a "speed" and "direction" (both built-in local variables), which Game Maker uses to update the instance's position automatically each step (an instance's position can also be modified directly using the built-in local "x" and "y" variables).
Here is an example of a more complex script from a platform game. Using this, the player can walk over hills and bumpy terrain.
Here is a piece of code that draws a simple 3D floor (the function
d3d_start
must be called beforehand).Manual
The manual that accompanies Game Maker is a document that has information on all the built-in functions and variables available in Game Maker, with the exception of action functions (the direct GML equivalents to drag-and-drop actions), and deprecated
Deprecation
In the process of authoring computer software, its standards or documentation, deprecation is a status applied to software features to indicate that they should be avoided, typically because they have been superseded...
variables and functions left in for backward compatibility, such as image_scale, which has been succeeded by image_xscale and image_yscale.
A notable example of a deprecated variable is image_single, which when changed to a sprite's subimage, will set image_speed to zero automatically, as well as setting image_index to the value image_single is set to.
Criticism
Common criticism towards Game Maker is its odd typing system, where variables can only be strings or real numbers, yet also be indexed like arrays. There is no way to make a variable hold an array, the name of the array implicitly accesses the zeroth element. As such, there is no way to pass an array as a script argument, except by passing a string holding the name of the array, which is then used to access the array itself. The other data structures are not very well integrated into the language, requiring a type unsafe index handle to the data structure, and requiring explicit deallocation (which has the potential for memory leaks). As well, they are only available to registered users.
The loose syntax of GML makes it easier to program in to an extent, but has the potential to cause very hard to read source code. The following is an example of what is possible:
Although not directly a part of the language, another common source of criticism is Game Maker's creation of .exe files that consist of a runner and the textual GML source, waiting until the end user runs the game to parse into an Abstract Syntax Tree
Abstract syntax tree
In computer science, an abstract syntax tree , or just syntax tree, is a tree representation of the abstract syntactic structure of source code written in a programming language. Each node of the tree denotes a construct occurring in the source code. The syntax is 'abstract' in the sense that it...
. This facilitates decompiling, and causes much slower start up times than necessary.