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

SOLVED What are some ways to create a menu system?

flyinian

Member
I am creating a menu system for my game and was wondering what methods are out there.

A little bit about what I'm doing,

What I have so far is several buttons. if one button is pressed it creates its items, if a different button is pressed if destroys the items from the last and creates its own.

All the buttons are shown to the player at the same time.

I've tried the, variable = !variable and haven't had any luck.
 

Slyddar

Member
Here's a tutorial I made on creating a menu system with sub menus. It doesn't use the mouse, but it might help you with the basis at least.

 

Yal

šŸ§ *penguin noises*
GMC Elder
I've tried the, variable = !variable and haven't had any luck.
Please elaborate. There's a lot of things you can do with inverting the value of a variable, but it doesn't magically make a menu appear :p

My preferred way to make menus is to have each menu window be its own object, and it contains a 2D array of menu events. Whichever menu was created last has the highest priority, and only that actually does anything when receiving input. Since the menu events (which is a text - script - icon - description tuple: text/description/icon are just visual, the script is run when the player presses "OK" on that menu option) are in a 2D array, the same system can be used for horizontal menus, vertical menus, and grid menus, and no matter the shape, different scripts or drawing loadouts in each cell lets you do a lot of customization (everything doesn't need to be uniform over the same menu).
 

flyinian

Member
Please elaborate. There's a lot of things you can do with inverting the value of a variable, but it doesn't magically make a menu appear :p

My preferred way to make menus is to have each menu window be its own object, and it contains a 2D array of menu events. Whichever menu was created last has the highest priority, and only that actually does anything when receiving input. Since the menu events (which is a text - script - icon - description tuple: text/description/icon are just visual, the script is run when the player presses "OK" on that menu option) are in a 2D array, the same system can be used for horizontal menus, vertical menus, and grid menus, and no matter the shape, different scripts or drawing loadouts in each cell lets you do a lot of customization (everything doesn't need to be uniform over the same menu).
Here is the code for my menu system:

Each menu button, when clicked, creates their own items using "instance_create_.." and destroys it with "instance_Destroy".

I got it to where I can click on the menu button and it'll create its content. However, I have to click on a different menu button twice to create the items of the second menu item.

The first click is deleting the menu items contents of the first menu button and then the second click is creating the contents of the second menu button. It should just be one click to open/close the menus.

The menu buttons are laid out horizontal and all are showing at the same time. The player should be able to click on any menu button to show its contents and then click on a different menu button to show that buttons contents.

GML:
if (mouse_check_button_released(mb_left) && position_meeting(mouse_x, mouse_y, object1))
{
    
    object_control._ItemVisible = !object_control._ItemVisible;
    
    
    // menu item 1
        if(!instance_exists(object2))
        {
        instance_create_depth(320, 96, 0, object2);
        };

        // menu item 2
        if(!instance_exists(object3))
        {
        instance_create_depth(4, 96, 0, object3);
        };
};


// destroy contents(menu items) of the menu buttons.
if(!object_control._ItemVisible)
{
instance_destroy(object2);
instance_destroy(object3);
};

I hope the above makes sense. I am still experimenting with the code .
 

flyinian

Member
I figured it out.

For those looking for help with a similar problem, here is the code I used.

object_control has "ItemVisible = id" in its create event. "ItemVisible can also be a global variable.

"id" is the unique instance identification to the specific instance.

GML:
if (mouse_check_button_released(mb_left) && position_meeting(mouse_x, mouse_y, object1) && object_control._ItemVisible != id)  // if clicked and id isn't selected
{// set id to clicked instance
    object_control._ItemVisible = id;
        
}
else
{
if(mouse_check_button_released(mb_left) && position_meeting(mouse_x, mouse_y, object1) && object_control._ItemVisible == id)  // if id is already selected
{    // set id to not selected
    
    
    object_control._ItemVisible = !id;
};
};


    if(object_control._ItemVisible = id) // if id is selected
        {
        // your menu items spawn code/ other goes here.
        }
        else // if id is no longer selected
        {
        // your menu items deletion code/ other goes here.
         };
 

flyinian

Member
Or you could use true and false. Using the ! operator on something that isn't a boolean is usually a good sign that you don't quite understand what you're doing.
Where you referring to:

GML:
object_control._ItemVisible = !id;
If so, is it meant to be:

GML:
obj_P_Combat_Menu_Ctrl._ItemVisible = false;
 

Nidoking

Member
Well, I don't know why you suddenly changed the object id there, but indeed, false seems to be the correct value for a variable called _ItemVisible if you want the Item to be Not Visible.

Then again, it looks like you're also checking for that variable to be equal to an instance's id later, so... if it's an id variable rather than a boolean, a good value that won't match any instance is noone.
 
Top