GameMaker Menu object not appearing after following a tutorial

S

SARAndipitii

Guest
Hi!

So I'm a beginner when it comes to GMS and coding in general. I followed a tutorial for creating menus:

https://www.youtube.com/watch?v=fWAhi10q1ZE&

I followed everything to the letter with the exception of the general layout of the menus, some visual elements and controls, but I don't see my object at all. It's already added to the room and "visible" is checked.

Below is the code I'm using.

Create
Code:
gui_width = display_get_gui_width();
gui_height = display_get_gui_height();
gui_margin = 32;

menu_x = gui_width+200;
menu_y = gui_height - gui_margin;
menu_x_target = gui_width - gui_margin;
menu_speed = 25; //lower is faster
menu_font = font_main;
menu_itemheight = font_get_size(font_main);
menu_committed = -1;
menu_control = true;

menu[0] = "Continue";
menu[1] = "New Game";
menu[2] = "Settings";
menu[3] = "Credits";
menu[4] = "Exit";

menu_items = array_length_1d(menu);
menu_cursor = 2;

Draw GUI
Code:
draw_set_font(font_main);
draw_set_halign(fa_left);
draw_set_valign(fa_middle);

for (var i = 0; i < menu_items; i++)
{
    var offset = 2;
    var txt = menu[i];
    if (menu_cursor == i)
    {
        txt = string_insert("> ", txt, 0);
        var col = c_white;
    }
    else
    {
        var col = c_gray;
    }
    var xx = menu_x;
    var yy = menu_y - (menu_itemheight * (i * 1.5));
    draw_set_color(c_white);
    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);
}

Step
Code:
if (menu_control)
{
    if (keyboard_check_pressed(vk_up)) or keyboard_check_pressed(ord("W"))
    {
        menu_cursor++;
        if (menu_cursor >= menu_items) menu_cursor = 0;
    }
    if (keyboard_check_pressed(vk_down)) or keyboard_check_pressed(ord("S"))
    {
        menu_cursor--;
        if (menu_cursor < 0) menu_cursor = menu_items-1;
    }
    if (keyboard_check_pressed(vk_enter)) or keyboard_check_pressed(vk_space)
    {
        menu_x_target = gui_width+200;
        menu_committed = menu_cursor;
        menu_control = false;
    }
}

if (menu_x > gui_width+150) && (menu_committed != -1)
{
    switch (menu_committed)
    {
        case 0: game_end(); break;
    }
}

I'm not getting any syntax errors, but I have no idea why it's not appearing.

What am I doing wrong?
 

Sk8dududu

Member
You cannot see the object? Or you cannot see anything that the object draws?
If your object doesn't have a sprite, you won't be able to see it, regardless of it being visible or not.
 

woods

Member
first thing that comes to mind is (just a guess)
in the draw event, draw_self();
 
Last edited:

Corey

Member
The thing about Draw GUI event is it's classified as a Draw event that follows the screen, and only draws GUI elements. If it's set to only draw GUI, it will do just that and only that and ignore other concepts defined by the sprite itself. You will have to declare the sprite of the object; in this case, create a Draw event and use this code:

draw_sprite(sprite, subimg, x, y);
 
You cannot see the object? Or you cannot see anything that the object draws?
If your object doesn't have a sprite, you won't be able to see it, regardless of it being visible or not.
If you use the Draw GUI and draw text (which is what is being done by the OP) you do not need a sprite. This is how you draw text menus.

first thing that comes to mind is (just a guess)
in the draw event, draw_self();
This is not needed as the Draw GUI event contains all the drawing of the text that is needed.

The thing about Draw GUI event is it's classified as a Draw event that follows the screen, and only draws GUI elements. If it's set to only draw GUI, it will do just that and only that and ignore other concepts defined by the sprite itself. You will have to declare the sprite of the object; in this case, create a Draw event and use this code:

draw_sprite(sprite, subimg, x, y);
You do not do this as there is no sprite, and the menu is a series of draw text commands.

The problem is that the OP has not actually followed the tutorial exactly and has one single mistake.
I followed everything to the letter with the exception of the general layout of the menus, some visual elements and controls, but I don't see my object at all. It's already added to the room and "visible" is checked.
You have not followed it exactly. Even clicking on that YouTube link it shows immediately the mistake that you have made.
In the tutorial video, the line is meant to be:
Code:
menu_x = gui_width;//+200;
but you have still got it as:
Code:
menu_x = gui_width+200;
This means that your menu is being drawn 200 pixels off the right side of the screen.
 
@BaBiA Game Studio
He said "I cannot see the object". If you have no sprite then no matter what you draw, you still can't see the object. You can just see what the object draws.
Yes, but he is following a tutorial that draws a text menu, so it does not require the object to have a sprite just to draw the text options of the menu. If it was a sprite-based menu (a background image etc) then yes you would be correct. But if you are trying to draw a load of text and say that you cannot see your object, then it seems pretty obvious that the problem is that the text is not drawing. And considering that the OP is drawing all the text outside of the screen it is no wonder that the text does not show up. :)
 

Sk8dududu

Member
Yes, but he is following a tutorial that draws a text menu, so it does not require the object to have a sprite just to draw the text options of the menu. If it was a sprite-based menu (a background image etc) then yes you would be correct. But if you are trying to draw a load of text and say that you cannot see your object, then it seems pretty obvious that the problem is that the text is not drawing. And considering that the OP is drawing all the text outside of the screen it is no wonder that the text does not show up. :)
I didn't find it obvious. I tend to take things quite literally though.
 
S

SARAndipitii

Guest
You cannot see the object? Or you cannot see anything that the object draws?
If your object doesn't have a sprite, you won't be able to see it, regardless of it being visible or not.
first thing that comes to mind is (just a guess)
in the draw event, draw_self();
The thing about Draw GUI event is it's classified as a Draw event that follows the screen, and only draws GUI elements. If it's set to only draw GUI, it will do just that and only that and ignore other concepts defined by the sprite itself. You will have to declare the sprite of the object; in this case, create a Draw event and use this code:

draw_sprite(sprite, subimg, x, y);
As BaBiA has said, I'm trying to create a text-based menu in which I would not need a sprite.

Code:
menu_x = gui_width;//+200;
but you have still got it as:
Code:
menu_x = gui_width+200;
This means that your menu is being drawn 200 pixels off the right side of the screen.
I've changed it back and it still doesn't show.
 

Yal

šŸ§ *penguin noises*
GMC Elder
How about adding this line to the top of your drawing script, before the loop?

Code:
draw_set_color(c_red)
draw_set_alpha(1)
draw_arrow(display_get_gui_width()*0.5,display_get_gui_height()*0.5,menu_x,menu_y,10)
If you see an arrow or a line, it will point you from the center of the GUI layers towards where the menu is (telling you how to adjust coordinates). If you don't see an arrow, the menu object doesn't exist in the room or is invisible. If you see an arrow but not a menu (i.e. the arrow points to a place on-screen), there's a problem with the font.
 
I've changed it back and it still doesn't show.
Then the other problem is that you are using left-aligned text instead of right-aligned text (in your Draw GUI event).
Your code:
Code:
draw_set_halign(fa_left);
Tutorial code:
Code:
draw_set_halign(fa_right);
Using left-aligned means that the left edge of the text will start from the position that it is draw, so it will continue off the edge of the screen. Right-aligned will put the right edge of the text at the position you are drawing.
 
B

BASTAMASTA

Guest
hello there.
i had the same problem and i found out that if i just do this:

GML:
gui_width = display_get_width() - 200;
and

Code:
menu_x_target = gui_width - gui_margin - 120
it works just fine, the problem was with the co-ordinates.
 
Top