• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Better understanding on arrays

B

Blakkid489

Guest
So I believe I get the gist of this system. From what I understand. . .

mmenu[0] = "Start game" //name of the option
mmenu[1] = 0 //numbered position

I think that's right. But now I'm lost on setting the rest of the menu up. How would this go normally?
 
T

tserek

Guest
Arrays are variables, basically. The setting is correct for 1d array, mmenu[0] holds a string and mmenu[1] holds a number. What you're about to achieve with it?
 
T

TDSrock

Guest
I wrote out a tutorial regarding 1D and 2D arrays a while back on the old GMC. You might want to check it out HERE.

Now what are you exactly trying to achieve? You give no real info on what you are doing here mate.
 
W

whale_cancer

Guest
Seems like you want to make a menu.

I would have the object that holds the array create a number of buttons (the same object) based on the array. Have the creator object pass the array values to the buttons in a variable called 'label' or something.

Have the buttons function based on what their label is (e.g. if label == "Start" room_goto(rm_start)). Have the buttons draw their label in text.
 
B

Blakkid489

Guest
Okay i see. My goal is to basically have a better way of coding my menu. My previous code would look like this:

Create Event:
Code:
mmenu = 0;
my_col = c_red;
alarm[0] = 0;
Alarm 0 Event:
Code:
alarm[0] = 10;
if my_col = c_red
my_col = c_white
else
if my_col = c_white
my_col = c_red
Draw Event:
Code:
if mmenu = 0
draw_set_color(my_col)
else
draw_set_color(c_dkgray)
draw_text(240,160,"Start Game")

if mmenu = 1
draw_set_color(my_col)
else
draw_set_color(c_dkgray)
draw_text(240,160,"Load Game")

if mmenu = 2
draw_set_color(my_col)
else
draw_set_color(c_dkgray)
draw_text(240,160,"Options")

if mmenu = 3
draw_set_color(my_col)
else
draw_set_color(c_dkgray)
draw_text(240,160,"Exit")
If anything, this is pretty basic and works fine but I wanna get a grasp of arrays and I figure menus is a good way to start.

So if I'm correct my create event should look like this. . .

Create event:
Code:
mmenu[0,0] = "Start Game" //Option name
mmenu[0,1] = 0 //option number

mmenu[1,0] = "Load Game"
mmenu[1,1] = 1

mmenu[2,0] = "Options"
mmenu[2,1] = 2

mmenu[3,0] = "Exit"
mmenu[3,1] = 3

Is this right or I think I'm over complicating this.
 
T

tserek

Guest
If i understand it you'd like to draw a current menu text blinking red and white?

create:
Code:
menu = 0;
text[0] = "Start Game";
text[1] = "Load Game";
text[2] = "Options";
text[3] = "Exit";

col_n = 0;
col[0] = c_white;
col[1] = c_red;

alarm[0] = 10;
draw:
Code:
draw_set_font(menufont);
draw_set_halign(fa_left);
draw_set_color(col[col_n]);

draw_text(240,160,string(text[menu]));

menu += keyboard_check_pressed(vk_right) + (-keyboard_check_pressed(vk_left));
if menu < 0 {menu = 3;}
if menu > 3 {menu = 0;}
alarm[0]:
Code:
alarm[0] = 10;

col_n += 1;
if col_n > 1 {col_n = 0;}
Alternative yuo can use also switch statement instead arrays..
Code:
switch col_n
{
case 0: draw_set_color(c_white); break;
case 1: draw_set_color(c_red); break;
}

switch menu
{
case 0: draw_text(240,160,"Start game"); break;
case 1: draw_text(240,160,"Load game"); break;
case 2: draw_text(240,160,"Options"); break;
case 3: draw_text(240,160,"Exit"); break;
}
 
Last edited by a moderator:
Top