GameMaker Trouble with my menu object

Ekit

Member
Hi,

I'm having some issues with my starting menu. I have a room called room_menu with only two spriteless objects in it.

One is obj_controller and all it does is quit the game when you press Esc.

The other is obj_menu that handles the drawing of the menu and the selection of the different menu options.

Everything is working perfectly with the menu so far, except for when I exit the menu and enter the game proper and then go back to room_menu. When I do that the menu does't show up and I have no idea why! It works perfectly when you enter the room the first time, but not when you come back to the room later.

Any help would be greatly appreciated.

The code for obj_menu:

Create - GUI and variables and menu setup
GML:
/// @description GUI and variables and menu setup

#macro SAVEFILE "Save.sav"

gui_width = room_width/2;//display_get_gui_width();
gui_height = room_height;///2;//display_get_gui_height();
gui_margin = 50; //Ger oss marginaler så vi inte ritar texten precis vid kanten

menu_x = gui_width;// +200; //x-positionen för vår meny
menu_y = gui_height - gui_margin + 800;
menu_y_target = gui_height - gui_margin; //var vi vill att menyn ska landa
menu_speed = 15; //hastigheten menyn åker in. lower is faster
menu_font = fnt_menu;
menu_itemheight = font_get_size(fnt_menu);
menu_committed = -1;
menu_control = true;

menu[3] = "New Game";
menu[2] = "Continue";
menu[1] = "Options";
menu[0] = "Quit";

menu_items = array_length_1d(menu); //hur många items det finns i menyn

menu_top = menu_y - ((menu_itemheight * 1.5) * menu_items)-800; //-800 för vi lägger till +800 i menu_y

menu_cursor = 3;

//Disabla musen om spelaren inte rör den på ett tag
mouse_disable = false;
mouse_xpos = mouse_x;
alarm[0] = 120;
Step - Control Menu

GML:
/// @description Control Menu

//Item ease in
menu_y += (menu_y_target - menu_y) / menu_speed;

//Keyboard Controls
if (menu_control)
{
    //Jag vet inte vrf jag måste hårdkoda detta men det funkar nu iaf. 💩💩💩💩 programmering.
    if (keyboard_check_pressed(vk_up)) || (keyboard_check_pressed(ord("W"))) || (gamepad_button_check_pressed(0, gp_padu)) || (gamepad_button_check_pressed(4, gp_padu))
    {
        menu_cursor++;
        if (menu_cursor >= menu_items) menu_cursor = 0;
    }
    //Jag vet inte vrf jag måste hårdkoda detta men det funkar nu iaf. 💩💩💩💩 programmering.
    if (keyboard_check_pressed(vk_down)) || (keyboard_check_pressed(ord("S"))) || (gamepad_button_check_pressed(0, gp_padd)) || (gamepad_button_check_pressed(4, gp_padd))
    {
        menu_cursor--;
        if (menu_cursor < 0) menu_cursor = menu_items-1;
    }
    //Jag vet inte vrf jag måste hårdkoda detta men det funkar nu iaf. 💩💩💩💩 programmering.
    if (keyboard_check_pressed(vk_space)) || (keyboard_check_pressed(vk_enter)) || (gamepad_button_check_pressed(0, gp_face1)) || (gamepad_button_check_pressed(4, gp_face1))
    {
        menu_y_target = gui_height - gui_margin + 800;
        menu_committed = menu_cursor;
        scr_screenshake(4,30);
        menu_control = false;
    }
    //Mus-kontrollerad meny
    var mouse_y_gui = device_mouse_y_to_gui(0);
    if (mouse_y_gui < menu_y) && (mouse_y_gui > menu_top) && (mouse_disable == false)
    {
        menu_cursor = (menu_y - mouse_y_gui) div (menu_itemheight * 1.5);
        if(mouse_check_button_pressed(mb_left))
        {
            menu_y_target = gui_height - gui_margin + 800;
            menu_committed = menu_cursor;
            scr_screenshake(4,30);
            menu_control = false;
        }
    }
}

if (menu_y > gui_height - gui_margin + 750) && (menu_committed != -1)
{
    switch (menu_committed)
    {
        case 3: default: room_goto_next(); break;
        case 2:
        {
            if (!file_exists(SAVEFILE))
            {
                room_goto_next();
            }
            else
            {
                if (file_exists("savedgame.sav"))
                {
                    var _wrapper = scr_load_json_from_file("savedgame.sav");
                    var _list = _wrapper[? "ROOT"];
   
                    for (var i = 0; i < ds_list_size(_list); i++)
                    {
                        var _map = _list[| i];
       
                        var _obj = _map[? "obj"];
                        with (instance_create_layer(0,0,layer,asset_get_index(_obj)))
                        {
                            //Här hämtas allt som har sparats
                            x = _map[? "x"];
                            y = _map[? "y"];
                            room = _map[? "room"];
                            global.hero_health = _map[? "health"];
                            global.sword_level = _map[? "sword_level"];
                        }
                    }
   
                    ds_map_destroy(_wrapper);
                    show_debug_message("Game Loaded!");
                }
                else
                {
                    show_debug_message("ERROR! No Savefile Found!");
                }
            }
        }
        break;
        case 0: game_end(); break;
    }
}
Alarm 0 - Aktiverar musen om spelaren rört den

GML:
/// @description Aktiverar musen om spelaren rört den
if (mouse_xpos == mouse_x)
{
    mouse_disable = true;
}
else
{
    mouse_disable = false;
}
mouse_xpos = mouse_x;
alarm[0] = 120;
Draw GUI - Draw

GML:
/// @description Draw

draw_set_font(fnt_menu);
draw_set_halign(fa_center);
draw_set_valign(fa_bottom);

for (var i = 0; i < menu_items; i++)
{
    var offset = 2;
    var txt = menu[i];
    if (menu_cursor == i)
    {
        txt = string_insert(txt,"--", 2); // fixar streck runtom alternativet man markerat
        var col = c_yellow;
    }
    else
    {
        var col = c_black;
    }
    var xx = menu_x;
    var yy = menu_y - (menu_itemheight * (i * 1.5));
    draw_set_color(c_black);
    draw_text(xx-offset,yy,txt);
    draw_text(xx+offset,yy,txt);
    draw_text(xx,yy+offset,txt);
    draw_text(xx,yy-offset,txt);
    draw_set_color(col);
    draw_text(xx,yy,txt);
}
Game start - Läs in alla globala variabler

GML:
/// @description Läs in alla globala variabler

scr_global_variables_create();
The script scr_global_variables_create is just a script for creating some variables relating to the player's levels and health. Here it is:

scr_global_variables_create

GML:
///@description Creates all the global variables
global.sword_level = 5;

//Player health
global.hero_health = 100;

//Player damage så damage-surfacen funkar
global.player_damage = 0;
This is my first post here so I hope I did everything correct. Feel free to ask questions and I will expand as much as I can.

Thanks in advance to anyone who can figure out what the hell I'm doing wrong. :)
 

Ekit

Member
UPDATE: After doing some testing I noticed that I can still pick options in the menu when I return to it, it just doesn't show up on screen.

Again, I have no idea why it does this. Is something wrong in my Draw Event?
 

Ekit

Member
SECOND UPDATE: I resolved the issue. The problem was that I had another object in the other rooms that handled the player's health bar that called display_set_gui_size. I changed the Draw GUI Event in obj_menu to a Draw Event and this fixed the issue.
 
Top