Issue with switch to set the game on fullscreen and viceversa

M

MrRoot

Guest
Good night everyone.

So, after watching Shaun Spalding's video on menus, I chose to make an options menu which looks like the following:



This is what the step code looks like for the object that draws the menu:

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)
{
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_space),0);
if (push == 1) scr_options();
and this is what the scr_options' code looks like:

Code:
switch (mpos)
{
    case 0: break;
   
    case 1:
    {
        if (global.fullscreen = 0)
        {
        window_set_fullscreen(true);
        ini_open("config.ini");
        global.fullscreen = ini_write_real("fullscreen_config","fullscreen",1);
        ini_close();
        room_goto(rm_options)
        break;
        }
       
        if (global.fullscreen = 1)
        {
        window_set_fullscreen(false);
        ini_open("config.ini");
        global.fullscreen = ini_write_real("fullscreen_config","fullscreen",0);
        ini_close();
        room_goto(rm_options)
        break;
        }
    }

    case 2: room_goto(rm_menu); break;
   
    default: break;
}
The problem is: when I press Fullscreen once, the game turns to fullscreen but when I press it again, it doesn't do anything. I have to go back to the main menu again and then return to the options menu to press it and then it works again (only once, just like before).

What am I missing?

Thanks in advance.
 
Last edited by a moderator:
T

The5thElement

Guest
I'm still somewhat new to GM:S but have you tried using if/else if instead of two if statements?

Code:
if (global.fullscreen = 0){
        window_set_fullscreen(true);
        global.fullscreen = 1;
        ini_open("config.ini");
        ini_write_real("fullscreen_config","fullscreen",1);
        ini_close();
        room_goto(rm_options)
        break;
}else if (global.fullscreen = 1){
        window_set_fullscreen(false);
        global.fullscreen = 0;
        ini_open("config.ini");
        ini_write_real("fullscreen_config","fullscreen",0);
        ini_close();
        room_goto(rm_options)
        break;
}
And if that doesn't work you could try this instead.

Code:
if (global.fullscreen = 0){
        window_set_fullscreen(true);
        global.fullscreen = 1;
        ini_open("config.ini");
        ini_write_real("fullscreen_config","fullscreen",1);
        ini_close();
}
if (global.fullscreen = 1){
        window_set_fullscreen(false);
        global.fullscreen = 0;
        ini_open("config.ini");
        ini_write_real("fullscreen_config","fullscreen",0);
        ini_close();
}
room_goto(rm_options)
break;
Sorry if these aren't of any help.
 
Last edited by a moderator:
M

MrRoot

Guest
I'm still somewhat new to GM:S but have you tried using if/else if instead of two if statements?

Code:
if (global.fullscreen = 0){
        window_set_fullscreen(true);
        global.fullscreen = 1;
        ini_open("config.ini");
        ini_write_real("fullscreen_config","fullscreen",1);
        ini_close();
        room_goto(rm_options)
        break;
}else if (global.fullscreen = 1){
        window_set_fullscreen(false);
        global.fullscreen = 0;
        ini_open("config.ini");
        ini_write_real("fullscreen_config","fullscreen",0);
        ini_close();
        room_goto(rm_options)
        break;
}
And if that doesn't work you could try this instead.

Code:
if (global.fullscreen = 0){
        window_set_fullscreen(true);
        global.fullscreen = 1;
        ini_open("config.ini");
        ini_write_real("fullscreen_config","fullscreen",1);
        ini_close();
}
if (global.fullscreen = 1){
        window_set_fullscreen(false);
        global.fullscreen = 0;
        ini_open("config.ini");
        ini_write_real("fullscreen_config","fullscreen",0);
        ini_close();
}
room_goto(rm_options)
break;
Sorry if these aren't of any help.
Thank you. The first one did it, although I deleted the room_goto() since it wasn't really useful.

Thanks again for your help. Been struggling with this for two days already :/
 

NightFrost

Member
Also, in case you didn't catch it, your problem was that ini_write_real does not give a return value so your global.fullscreen wasn't getting changed, or was being set to some unknown value.
 
Top