This article is about GML, the scripting language of Game Maker. For other uses of GML, see GML. Game Maker Language (GML) is an interpreted 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 translate to GML rather than being separate from it. GML may stand for: Generalized Markup Language Geography Markup Language Game Maker Language, the scripting language of Game Maker. ...
In computer programming, an interpreted language is a programming language whose programs may be executed from source form, by an interpreter. ...
Application software is a subclass of computer software that employs the capabilities of a computer directly and thoroughly to a task that the user wishes to perform. ...
This article is about Game Maker for Microsoft Windows. ...
Prof Dr. Mark H. Overmars (born 29 September 1958) is a Dutch programmer and teacher of programming (particularly of games). ...
A common misconception is that languages such as Pascal, ASM, and C++ can be directly used in GML. This is incorrect, and is a common mistake due to GML's ability to utilise Pascal and C++ style syntax (e.g. "&&" is interchangeable with "and"). Pascal is a structured imperative computer programming language, developed in 1970 by Niklaus Wirth as a language particularly suitable for structured programming. ...
See the terminology section, below, regarding inconsistent use of the terms assembly and assembler. ...
C++ (pronounced see plus plus, IPA: ) is a general-purpose programming language with high-level and low-level capabilities. ...
For other uses, see Syntax (disambiguation). ...
Libraries
In Game Maker, a set of drag-and-drop actions is called a library. In the GM interface, these libraries are displayed as tabs containing icons called actions. Each action is a GML script or function that user can use in the game. 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.
Extensions As of version 7.0 of Game Maker a new feature has been implemented that lets you include additional functions, libraries, and DLLs to extend the functionality of Game Maker. There are many extensions by the members of the Game Maker Community, that handle everything from new music formats to networking to new drawing routines and colors to using the Wii Remote etcetera. All files are stored in a container file called a GEX (Game maker EXtension) which is installed from within the Game Maker interface. The Wii Remote, also nicknamed Wiimote, is the primary controller for Nintendos Wii console. ...
GML syntax and semantics GML is a language similar to C++. GML statements can be separated by semicolon, but GM does not force this. Whenever GM is expecting a semicolon after a statement, it will assume it is there, regardless of whether it exists or not. Other than separating statements from each other, GM mostly ignores whitespace in code (except inside strings). 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. For example, the following line would always generate an error because it would first compare if the variable "answer" is the same as what was returned from the get_string function and then compare if the boolean value was equal to "Yes" (a comparison of a real value and a 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 "==" for boolean comparison. However, the double equal sign "==" may also be used as comparison operator but not an assignment operator. GML also allows increment/decrement operators. The code g += 1; is the same as g = g + 1; . The same function applies to the operators -=, *=, /= . Game Maker does not allow ?: Syntax.
Functions GM has a large library of built in functions available that covers most of the basic functionality. One can also create scripts which can be called in the same way functions are. The drawing functions in GML make use of the Direct3D API. Direct3D is part of Microsofts DirectX API. Direct3D is only available for Microsofts various Windows operating systems (Windows 95 and above) and is the base for the graphics API on the Xbox and Xbox 360 console systems. ...
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. In Game Maker 7.0 a new extension mechanism was created which can be used to replace these functions. DLL is an abbreviation which can commonly mean: Data link layer, a layer in the OSI network architecture model Dynamically Linked Library, a binary application library file format in Microsoft Windows and IBM OS/2 (see the Dynamic linking section of the Library (computer science) article) Doubly Linked List, a...
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". In computer science, a pointer is a programming language data type whose value refers directly to (or âpoints toâ) another value stored elsewhere in the computer memory using its address. ...
When creating resources or instances at runtime, its unique ID is returned and may then be passed to other variables and functions.
Code samples Here is a simple example that would show "Hello World!" inside a popup dialog on screen: show_message("Hello World!"); Another example that would write the same text on the game window instead: (Note: because of the way GameMaker handles drawing functions, this code would have to be placed in the Draw event of an object) draw_text(0, 0, "Hello World!"); Here is a piece of code from a game using GML: // This is a comment /* this is a C-Style comment. */ /*temporary variable declaration. A temporary variable will be released at the end of a script. Note that this doesn't declare it to be of a specific type!*/ var xx, yy, nn; /* A conditional. another way of writing this is "if (can_shoot)" since booleans are the same as integers */ if (can_shoot = true) /* "==" can be substituted as a comparison operator */ { //This begins a block. You can also use "begin" like in pascal. /* Here you are setting the integer (pseudo-boolean) variable can_shoot to false, a constant equaling 0. */ can_shoot = false; /*Here you are setting the built-in alarm variable's 0th indice to 5. The alarm variable will count down to 0, and when it does hit 0, the alarm0 event will be triggered.*/ alarm[0] = 5; /*Here the temporary variable xx is defined implicitly as an integer, and the lengthdir_x function is used.*/ xx = x + lengthdir_x(14, direction); yy = y + lengthdir_y(14, direction); //This function creates a obj_bullet and then returns its instance id to nn. nn = instance_create(xx, yy, obj_bullet); /*The with statement allows you to access the fields of an object directly, without having to write statements like nn.speed or nn.direction.*/ 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[0] := 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 endif end Here is an example script from a platform game. Using this the player can walk on hills and bumpy terrain. if !place_free(x-4,y) { if place_free(x-4,y-4) { x-=4 y-=4 } else if place_free(x-3,y-5) { x-=3 y-=5 } else if place_free(x-2,y-6) { x-=2 y-=6 } } else x-=4 Here is an example of movement: if (keyboard_check(vk_nokey)) motion_set(0,0); if (keyboard_check(vk_left)) motion_set(180,4); if (keyboard_check(vk_up)) motion_set(90,4); if (keyboard_check(vk_right)) motion_set(0,4); if (keyboard_check(vk_down)) motion_set(270,4); And this is how to make an object face the current direction. Note that this code will NOT work with unregistered versions of Game Maker: image_angle = direction Unregistered users would have to use: image_single = direction/360*image_number; The manual The manual that accompanies Game Maker is a very complete document that has information on all the functions available in Game Maker, with the exception of deprecated functions and built in variables left in for backwards compatibility, such as image_scale, which has been succeeded by image_xscale and image_yscale. An online manual is provided here where you can pick a language and file type (.doc or .pdf) In computer software standards and documentation, deprecation is the gradual phasing-out of a software or programming language feature. ...
External links - Official GML Documentation
- YoYo Games official website
- Game Maker discussion forums
|