Game Maker: Array Tutorial


Game Maker is a development environment designed to let beginners quickly create their own simple games. Even though Game Maker can be used by those who have no programming experience by dragging and dropping action blocks, it also contains a powerful development language called GML. This contains all the features of any modern programming language, including the capability to use arrays of variables. Using arrays in Game Maker is very easy, and requires only a line or two of code to implement.

  • Start Game Maker and set up the game environment. Create a new room and an object, and place an instance of the object in the room.

  • Add a "Create" event for the object and place an "Execute a piece of code" action in it. Paste the following block of code into the window that opens when you double-click the action:


    character_info[0,0] = "Zed";

    character_info[0,1] = 0;

    character_info[0,2] = 36;

    character_info[1,0] = "May";

    character_info[1,1] = 4;

    character_info[1,2] = 348;

    character_info[2,0] = "Consuella";

    character_info[2,1] = 4;

    character_info[2,2] = 224;


    The above code creates a two-dimensional array, three variables across and three variables tall. Each of these nine locations are given a different value -- some strings and some integers.

  • Add a "Draw" event and place another "Execute a piece of code" action, this time inside of it. Paste the following lines into its code window:


    for (i=0; i<=2; i+=1)


    for (j=0; j&lt;=2; j+=1)






    This prints the entire contents of the array to the screen, by way of two nested "for loops." The first loop runs three times, and during each iteration the inner loop runs three times, so that all nine values in the array are drawn.

  • Run your game to see the array at work. Arrays can be used in this way to store all kinds of data, whether scores, object positions, items in an inventory, or even lines in a multiple-choice conversation with a character in the game.

Related Searches


  • Photo Credit Yagi Studio/Photodisc/Getty Images
Promoted By Zergnet


You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!