Jump to: navigation, search

Game Maker Language

GML, or the Game Maker Language, is a scripting language created by Mark Overmars for use in Game Maker. GML allowed users to expand their projects beyond the limitations of Drag and Drop, as many functions can only be accessed in GML form. GML can be produced by dragging the "Execute a piece of code" tile within an object's editor. Opening this tile will present a code editor, in which you can write GML.

GML takes on a syntax similar to that of C, thus making it a potential entry point into the world of programming for new users.

Using GML

This is an example of how basic GML can be written:

  Block comments are set off like this

// Single-line comments are set off with //, and can be started everywhere

// Variables in GML are declared implicitly
variable1 = 5 // Assigns an integer to variable1, creating it if it doesn't exist.
variable2 = 6.432 // Assigns an integer to variable2, creating it if it doesn't exist.
variable3 = "Hello World!" // Assigns a string to variable2, creating it if it doesn't exist.
variable4[5] = 25 // Assigns an integer to index 5 of variable4. Previous indices are invalid.
variable5 = true // Assigns a boolean value to variable5, same as assigning it to 1.

// Out-of-scope declarations
global.variable1 = 0 // Assigns variable1 in the global namespace
object0.variable1 = 0 // Assigns variable1 in the first instance of object0
(100001).variable1 = 0 // Assigns variable1 in the instance with id 100001

// Semicolons are optional, usually.
// And GML is weakly typed.
variable1 = 6.5;
variable1 = "Hello, world!"
variable1[1] = 7
variable1[2] = "Goodbye";

// Control statements
if variable1  // Converts variable1 to boolean, testing if it is >= .5.
{  }
if (variable1) // A more "proper," but unnecessary way of writing the above
{  }

// The for loop
for(i = 0 i < 10 i += 1) {
for(i = 0; i < 10; i += 1) {
for(i = 0; i < 10; i += 1;) {
for({i = 0; j=0}; i < 10; {i += 1; j+=i}) {

// Demonstrating how to show a message inside of a message box through various means
show_message("Hello World!")

// Some typical 'if' statements
if variable1 = 4 show_message("Variable 1 = 4") else show_message("Variable1 does not = 4")

if variable2 <= 10 and variable1 >= 1 {
   variable2 += 2
   variable1 -= 1

// GML does offer explicit declaration for type 'var'.
// Variables declared explicitly last until the end of the code in which they are declared
var variable6, variable7; // The semicolon is necessary to separate statements from declarations
variable6 = "A new value!"
variable7 = 82;

There are many differences here between C and GML, although most C styles are supported within GML.

To begin with, GML does not require variable types to be declared before the variable itself can be assigned a value. For example, integers, strings, floating point numbers and Boolean values here have all been declared by simply stating the desired variable name and forcing it to equal a specific value.

The next thing to notice is that GML does not require a semi-colon in order to finish an instruction. Although it supports this feature, it does not require it for code to be run successfully.

Continuing the trend of loosely following laws, we can see during the 'if' statements that only a single equal sign is needed to check a particular value, as opposed to C's '=='. The double equal sign is also supported, but obviously not needed. Also within the 'if' statement is a lack of parentheses to indicate the expression to be evaluated. Again, this is supported but not a requirement.

Personal tools