• 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!

GameMaker [SOLVED] Menu controls stop working after choosing a menu option

Y

Yorollimor

Guest
Hey everyone!

I've been following the marvelous tutorials of "Friendly Cosmonaut" and am now working on a menu system.

My problem now is that, after comparing the code over and over again, changing variables, I don't know anymore.

The controls work perfectly in the main menu, I can go up, down, it highlights where I am etc. But when I press "Enter" to choose an option to go to a sub-menu (e.g. "Settings") the controls just stop working entirely.

I am using the lmb and rmb for going up and down, hence the "mouse_check_button_pressed".

Here is the code:

Step:
Code:
input_up_p        = mouse_check_button_pressed(global.key_up);
input_down_p    = mouse_check_button_pressed(global.key_down);
input_enter_p    = keyboard_check_pressed(global.key_enter);


var ds_grid = menu_pages[page], ds_height = ds_grid_height(ds_grid);

var ochange = input_down_p - input_up_p;

         
    if (ochange != 0)
    {
        menu_option[page] += ochange;
 
        if(menu_option[page] > ds_height-1) { menu_option[page] = 0; }
        if(menu_option[page] < 0)            { menu_option[page] = ds_height -1;}
    }

 


 
 
    if (input_enter_p)
    {
        switch(ds_grid[# 1, menu_option[page]])
        {
            case menu_element_type.page_transfer:
                page = ds_grid[# 2, menu_option[page]];
                break;
     
        }

    }
Create:
Code:
page =0;

menu_pages = [ds_menu_main, ds_menu_new_game_settings, ds_settings, ds_audio, ds_controls];

var i = 0, array_len = array_length_1d(menu_pages);
repeat(array_len)
{
    menu_option[i] = 0;
    i++;
}
A snippet of my create code, the rest is just the database and some basic variables.

It has to be a problem in the Step event, because after I press "Enter", the UI is still drawn exactly as it is supposed to, just the controls stop working.

If there is a similar post in the forum then I am sorry - I tried to look for one but didn't find any.

Just saying again that this code is (almost) 1:1 copied from "Friendly Cosmonaut" 's Menu tutorial on YouTube!

Hope I gave enough information!
 
Y

Yorollimor

Guest
I also just realised that when I am in a sub-menu and press "Enter", I get to the correct sub-menu of that option as well, so the only thing that doesn't work is the "up" and "down" and I still have no idea why.
 
Y

Yorollimor

Guest
Welp, problem solved! It wasn't a problem with the step events, but with the draw event after all. I don't know why it worked on the first screen but never on the ones after it, but oh well!

here is what my mistake was:

"original code":
Code:
var ltx = start_x - x_buffer, lty, xo;

var yy = 0; repeat (ds_height)
{
    lty = start_y + (yy*y_buffer);
    c=c_white;
    xo = 0;
  
    if (yy == menu_option[0])
    {
        c = c_orange;
        xo = -(x_buffer/2);
    }
    draw_text_color(ltx+xo,lty,ds_grid[# 0,yy],c,c,c,c,1);
    yy++;
}
correct code:
Code:
var ltx = start_x - x_buffer, lty, xo;

var yy = 0; repeat (ds_height)
{
    lty = start_y + (yy*y_buffer);
    c=c_white;
    xo = 0;
  
    if (yy == menu_option[page])
    {
        c = c_orange;
        xo = -(x_buffer/2);
    }
    draw_text_color(ltx+xo,lty,ds_grid[# 0,yy],c,c,c,c,1);
    yy++;
}
forgot to put the "page" variable for the array-access for "menu_option". don't ask me how that happened.

Anyway, mystery solved!
 
Top