GML (an acronym for "Game Maker Language") is a scripting programming 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 are based on GML rather than being separate from it.
GML has syntax and structures similar to other well-known programming languages like C++ and Pascal, such as the switch structure and loops.
Many of Game Maker's features are accessible through the drag-and-drop interface, but GML extends the functionality by providing functions that are not usable through the drag-and-drop interface, such as file handling functions, online multiplayer functions and functions to call external DLLs.
In Game Maker, GML is used in conjunction with drag-and-drop. Unless the entire project is written in GML, scripts cannot be called without drag-and-drop actions, but all drag-and-drop actions may also be written in GML. Most projects consist of both GML and drag-and-drop actions, depending on the programmer's preferences.
GML is interpreted rather than compiled. GML is compiled to byte-code at program startup to speed up execution.
Another example that would write the same text on game window instead: draw_text(0, 0, "Hello World!");
Here is a piece of code from a game using GML: var xx, yy, nn; if (can_shoot == true) { can_shoot = false; alarm* = 5; xx = x + lengthdir_x(14, direction); yy = y + lengthdir_y(14, direction); nn = instance_create(xx, yy, obj_bullet); with (nn) { speed = obj_tank.speed + 3; direction = obj_tank.direction; } }
GML also supports multiple other ways to write code, so the previous example could also look like this:
var xx yy nn; if can_shoot = true then begin can_shoot := false alarm* := 5 xx := x + lengthdir_x(14, direction) yy = y + lengthdir_y(14, direction) nn := instance_create(xx, yy, obj_bullet) with nn begin speed := obj_tank.speed + 3 direction := obj_tank.direction end end
GML makes a difference between statements and expressions. For example g < 1; is not a valid statement and GM will produce a parse error from that. Also, variable assignment is always a statement in GM, and cannot be used in expression. For example, the following line would always generate an error because it would first compare if the variable "answer" was the same as what was returned from the get_string function and then compare if the boolean value was equal to "Yes" (and comparison of real value and string will produce an error):
if ((answer = get_string("Yes or No?", "")) == "Yes")
Note that the equal sign "=" is a variable-assignment operator in statements and a boolean-comparison operator in expressions, unlike most C++ compilers which require "
The functions in Game Maker allow communication with DirectX.
GM also has built in functions for calling external DLLs. So any feature that is not provided natively through GM can be added using DLLs.
foo = "bar";.
GM has a large set of built in variables and constants. Each object in the game has a set of local variables such as "x" and "y". There are also some variables that are global which means that they relate to the whole game e.g. "score".
var local1, local2;. This will define the variables "local1" and "local2" to only exist within the scope of the current script. If the variable is not defined as local to the current script, it is automatically assumed to be local to the current object, which is running the script. By using the constant "global" as an object, a variable may also be defined to be in global scope like global.variable = "bar"; (global variables must always be also referenced using the global object). Similarly you may reference variables of another object using otherobject.variable = "foo";.
Note that the current object is changed inside "with" structure. For example, the following piece of code would produce "unknown variable" error, because the variable is not defined to the object in with statement:
foo = "bar"; with (other_object) { show_message(foo); }
However, we could avoid this by defining "foo" as local to the current script like:
var foo; foo = "bar"; with (other_object) { show_message(foo); }
Because GML has no boolean values, statements that require booleans values, such as "if" will evaluate any rounded value bigger than 0 as true, and 0 or any smaller value as false. Usuall, any value that returns only true or false will return 1 if true and 0 if false. In GML "true" and "false" are just constants that contain values 1 and 0.
When creating resources or instances at runtime using GML, it is possible to pass the ID, returned by the respective creation function, to any variable.
Game Maker Language | GML | Game Maker Language | Game Maker Language | Game Maker Language
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Game Maker Language".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world