Game Maker: Array Tutorial

Save

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)

    {

    draw_text(x+(60*i),y+(16*j),string(character_info[i,j]));

    }

    }

    }

    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.

References

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

Comments

You May Also Like

  • How to Write Math Arrays

    A math array is a way of writing multiplication expressions in terms of columns and rows of pictures or symbols that represent...

  • How to Make an RPG in Game Maker

    The creation of an RPG, or any computer game, can be an arduous but extremely rewarding process. Large software companies can spend...

  • How to Declare an Array in FoxPro Programming

    Visual FoxPro is an object-oriented and procedural programming language developed and deployed by Microsoft. Visual FoxPro is quick and simple to learn....

  • Interactive Math Array Games

    Math array games incorporate the idea of multiplication and division by arranging sets of numbers in rows or columns. Games designed around...

Related Searches

Check It Out

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

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