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

Need help fine tuning a menu

pixeltroid

Member
I have a basic functioning menu but I am looking to fine tune it a little.

Basically I have "Continue" on the top instead of "Start new" because thats where the cursor is located by default and there is the risk that the player may accidentally select "start new" and lose his progress.

Select "Start new" takes the player to a different menu where he gets to confirms if he wants to start a new game or go back to the menu where he can select "continue".

This is how it looks as of now.

titlemenu.gif

What I want to do is....

A. Make it so that the "continue" option is disabled if a saved file doesn't exist. So upon starting a game the player wont be able to select "continue" and maybe the word "continue" itself is written in gray (denoting that the button is currently inactive.
B. Make it so that if I select "start new", and a saved file doesn't exist, it takes me straight to the game without going to the sub-menu that requires player to confirm if he wants to start a new game.

--------------------------------------------------------------------------------------------------------------

Here are the codes for the obj_menu -- placed in "room_menu":

CREATION
Code:
menu[0] = "CONTINUE" //Continue from last save point
menu[1] = "START NEW" //start fresh game
menu[2] = "CREDITS"
menu[3] = "QUIT TO DESKTOP"
space = 32;
mpos = 0;
STEP
Code:
var move = 0;
move -= max(keyboard_check_pressed(vk_up),keyboard_check_pressed(ord("W")),0);
move += max(keyboard_check_pressed(vk_down),keyboard_check_pressed(ord("S")),0);

if (move != 0)
{   audio_play_sound(sfx_pickup2,10,false)
    mpos += move;
    if (mpos < 0) mpos = array_length_1d(menu) - 1;
    if (mpos > array_length_1d(menu) - 1) mpos = 0;
}

var push;
push = max(keyboard_check_released(vk_enter), keyboard_check_released(vk_shift),keyboard_check_released(vk_space),0);

if (push == 1) scr_menu();

DRAW
Code:
draw_set_halign(fa_left);
draw_set_valign(fa_middle);
draw_set_font(fnt_gametext);
draw_set_color(c_white);

var m;
for (m = 0; m < array_length_1d(menu); m +=1)
{
draw_text(x + space, y + (m * space), string(menu[m]))
}
draw_sprite(sprite_index, 0, x + 16, y + mpos * space);
--------------------------------------------------------------------------------------------------------------

This is the script that makes obj_menu work:

Code:
switch(mpos)
{

case 0:
   {
       audio_play_sound(sfx_pickup1,10,false)
       scr_loadgame(); 
       break;
    }

case 1: 
 {
 
  room_goto(room_submenu);
  break; 
    }
   
       

case 2:
    {   
     audio_play_sound(sfx_pickup1,10,false);
    instance_create(x,y,obj_fade_out);
        room_goto(room_credits);
        break;
    }

case 3:
    {
           game_end(); 
       
    }

}
--------------------------------------------------------------------------------------------------------------

This is the script for the submenu:

Code:
switch(mpos)
{   
case 0:
{
scr_resetvalues(); //resets saved values
room_goto(room_1); //go to first room and start playing
break; 
}

case 1:
room_goto(room_menu); //go back to the main menu
break; 
 }
the sub-menu object obj_submenu has the same structure as the main menu object.

--------------------------------------------------------------------------------------------------------------

The name of the saved file as it appears in the load and save script is "save.ini".

So basically....Im trying to make it so that:
- if "save.ini" doesnt exist, then "continue" in the main menu shouldn't work. Player can still move the cursor but pressing space doesn't do anything.
- if "save.ini" doesnt exist, then selecting "start new" on the main menu just takes you to the first room and you start playing.
- if "save.ini" exists, then selecting continue in the main menu works. AND selecting "start new" the sub-menu appears

How should I modify my code? Any help with examples would be greatly appreciated!
 

Alexx

Member
You could set flag at game start, something like:
Code:
if file_exists("Save.ini")
{
    global.saved=true;
}
else
{
    global.saved=false;
}
Then make menu element active or not depending on the value.
Likewise if present, then load in your data.
 
Create a new variable that checks for the file, and incorporate it into the relevant sections.

Create
Code:
sde = !file_exists("save.ini");
mpos = sde;
Step
Code:
if (mpos < sde) mpos = array_length_1d(menu) - 1;
if (mpos > array_length_1d(menu) - 1) mpos = sde;
Draw
Code:
for (m = 0; m < array_length_1d(menu); m +=1)
{
    if (!m && sde)
        draw_text_color(x + space, y + (m * space), string(menu[m]),c_gray,c_gray,c_gray,c_gray,1); // or "continue" if you'd rather it not show
    else
        draw_text(x + space, y + (m * space), string(menu[m]));
}
 

pixeltroid

Member
Create a new variable that checks for the file, and incorporate it into the relevant sections.

Create
Code:
sde = !file_exists("save.ini");
mpos = sde;
Step
Code:
if (mpos < sde) mpos = array_length_1d(menu) - 1;
if (mpos > array_length_1d(menu) - 1) mpos = sde;
Draw
Code:
for (m = 0; m < array_length_1d(menu); m +=1)
{
    if (!m && sde)
        draw_text_color(x + space, y + (m * space), string(menu[m]),c_gray,c_gray,c_gray,c_gray,1); // or "continue" if you'd rather it not show
    else
        draw_text(x + space, y + (m * space), string(menu[m]));
}
Thanks! That worked perfectly.


@ Alexx
Thanks! I used "if file_exists". Now selecting "start new" take you to the game if the save file doesn't exist, but if it exists it takes you to the sub-menu where you can either delete save data or return to the main menu.
 
Top