Array

What is an array ?

For the unitiated, an array is essentially a list of variables with a number next to it. Here are a few concrete example to clarify this concept that is often terribly explained.

Dialog System using arrays

Imagine, dialog being stored within an array. It would look like this:
//Create Event
text_ammount = 0;
text_box[0] = "This text will be drawn on screen when the text_ammount variable is equals to 0";
text_box[1] = "This text will be drawn on screen when the text_ammount variable is equals to 1";
text_box[2] = "This text will be drawn on screen when the text_ammount variable is equals to 2";

What does this mean ?

As stated in the text boxes, we would then use a variable called "text_ammount". This variable will increment everytime we press the required button to progress the dialog.
So what you would write in your draw event is:
draw_text(x,y,string(text_box[text_ammount]));

Now, if you are confused, let me explain it more clearly. The draw event is drawing a variable that can change. This is possible due to the fact that all variables in an array posess the same name, but a different number. What this code does is that it displays the variable's content on the screen. Everytime you press a button of your choice, the variable "text ammount" increments. Since the array number in the draw event is determined by the variable text_ammount, the text that will be displayed will be the next one.
Arrays serve as a method of scrolling through a set of variables.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution 2.5 License.