Array question



So I'm pretty new at this, so bear with me. I've watched the YouTube tutorials and read the forums and stuff and they're all great. Right now I'm just learning how to do stuff before I get into building a real game (got to walk before you can run as they say).

My current project consists of an array of text that appears on the screen when the player click a button. My problem is I can't figure out how to make it display anymore then the first entry in the array.

For example my D1 array would consist of:

text1[0] = "blah"
text1[1] = "blahblah"
text1[2] = "blahblahblah"

displaytext = 0

So under the "object-events-left release" heading, what should the code be to make it move down the array one at a time and display the next text when the button is clicked?

Thanks everyone. Like I said I'm really new at this.


A for loop is often used in this situation. You can use the for loop to cycle through the array and drawing each string one at a time. For example (no pun intended):
var array_length = array_length_1d(text);
for(var i = 0; i < array_length;i++){
inside the (parenthesis) of the for loop you can deduce what happens. The var i is initialized as a local variable to the value of zero. So, i = 0. The we draw the text draw_text(x,y,text[0]); I put the zero in as the element instead of "i" to show you what the i value actually holds. Then, after it's done with this, the for loop increments the i variable to that it is == 1. Now the next time it draws the text it chooses the second element of the array draw_text(x,y,text[1]) because "i" now equals 1. It does this until i is equal to the array_length in which case the text no longer draws because the for loop ends.

On a side note, you will want to increment the y value along with the i so that it doesn't draw in the same place. A possible modification could look like this.
for(var i = 0; i < array_length;i++){
     var _y = y+(i*30);
Here you can see a local variable _y (not to be confused with "y") is created and stores a value of y+(i*30); now if i is == 0 for example, this will draw at the y location but if were say i==2 then this would draw at the y+60 pixels location so it would draw below the original y.

Edit: I missed the detail about the left release event/button, however the logic of what I'm doing should lend insight hopefully.
Last edited: