Navigation
  • Home
  • Recent
  • Most Active
  • Popular
  • Blog
  • Credits
  • RSS
  •   Interaction
  • Register
  • Statistics
  •   Help
  • Suggestions
  • Contact Us
  • How to Edit
  • Help



  • [Edit]


    Game Maker Language (GML) 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.
    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").


        Game Maker Language
            Code Samples
            Libraries
            GML Syntax and Semantics
                Functions
                Variables
                    Scope
                    Types
                    Memory Allocation
                Instances and Resources
                The Manual

    top

    Code Samples
    Here is an 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 special begin-end comment.
        /

    /
      temporary variable declaration.
    A temporary variable will be removed 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)



    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

    alarm0
    = 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



    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)

    else
    x-=4


    top

    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 actions in the drag-and-drop interface. Each action is a GML script that user can use in the game and give values to it. Game Maker comes with a default library that contains the common actions used by most game makers, but it is also possible to create libraries using the Library builder provided separately from Game Maker.

    top

    GML Syntax and Semantics
    GML is a language similar to C++. It consists of statements and expressions and different kinds of structures. GML statements can be separated from each other by semicolon, but GM does not force this. Whenever GM is expecting a semicolon after statement, it will assume it is there, regardless of whether it exists. So, statements may be separated with whitespace also. Other than separating statements from each other, GM mostly ignores whitespace in code (except inside quoted strings).

    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 "==" for boolean comparison. However, the double equal sign "==" may also be used as comparison operator (but not assignment operator).

    top

    Functions
    GML has a built in library of 1178 functions available that cover most of the basic functionality. It is not possible to define new functions in GML, but in GM one can create script resources which can be called as functions.

    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.

    top

    Variables
    GML does not have compulsory declaration of variables similar to many other programming languages. A variable is created whenever a programmer first assign a value to it, such as 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".

    top

    Scope
    Even though one cannot define variables, one may define a scope of a variable using "var" statement like 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 one 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)

    However, we could avoid this by defining "foo" as local to the current script like:

    var foo;
    foo = "bar";
    with (other_object)

    top

    Types
    For the sake of simplicity GML only has three variable types. Every variable may hold each type of data without any type declarations.
      Strings are sets of ASCII characters that may be of any length. Only memory limits the size of strings.
      Real values are floating point numbers. However, ever since version 6, GM has suffered from inaccuracy problems with real values, which will cause many real value calculations to give slightly wrong results with big numbers. As of version 6.1, GM also allows hexadecimal representation for real values in code (preceded by '$').
      Arrays may be 1 or 2 dimensional arrays. Arrays may contain mix of strings and real values, but not arrays themselves. Arrays may not also be passed to a function and may not be returned from a function in GML. GM also has built in limits to index sizes. Neither index may not be bigger than 32000 and any single array may not contain more than total of 1000000 values.

    Because GML has no boolean values, statements that require boolean values, such as "if" will evaluate any rounded value bigger than 0 as true, and 0 or any smaller value as false. Usually, 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.

    top

    Memory Allocation
    GML automatically allocates memory for variables on demand, and uses dynamic typing so that assignments with different types of values are possible. For example, one can create a variable as an integer, and change its type to a string in two lines:
    intNumber=1;
    intNumber="some number";
    Unfortunately it is not possible to undefine variables in GM and free memory through that way. However, it is possible to destroy objects during the game, and any variable that was associated to that object will also be removed from the memory. Also, any variable local to scripts is removed from the memory after the script is run. For these reasons it is usually advisable to use either script or object local variables to store information instead of global variables so that it may be freed from the memory after it is no longer used.

    top

    Instances and Resources
    In Game Maker one can add plenty of different resources to a game, such as sprites, music, backgrounds, etc. However, GML has no particular pointer variable type to reference this in code. Thus, each resource and instance in Game Maker has a unique ID number, which is used to reference that particular resource or instance. Since it is possible to pass around numbers from one function to another, is also possible to pass instances and resources from one function to another. Upon the addition of a game resource, GM defines a constant (given upon creation of the resource, and editable afterwards) that contains that ID number for later use.

    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.

    top

    The Manual
    The Manual that accompanies GameMaker is a very complete document that has information on all the functions available in GameMaker, with the exception of a few functions that aren't supposed to be used but are only accesible for staying compliant with past versions (e.g. image_scale, which is outdated because of image_xscale and image_yscale, which give more control).
     
    Search more:
     

       
    Source Privacy License Download Contact Us Atlas
    Scientus.org Dictionary (Yet Another Wiki) RC : 1.39
    This article is licensed under the GNU Free Documentation License [copyleft]. It uses material from the Wikipedia article "Game Maker Language". link