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

Pressing F4 for fullscreen

Redcakes

Member
So I made a camera and I have it working. The only thing now is I want to allow players to press F4 to switch it into fullscreen.
I have this code in a persistent object:

if(global.fullscreen = false){
window_set_size(displayWidth,displayHeight);
}


...which sets the camera to the settings I have specified in other lines of code BUT should only do so if the variable "fullscreen" is set to false.
So here in a different persistent object I have this code:
global.fullscreen = false;

if keyboard_check(vk_f4){
global.fullscreen = true;
window_set_fullscreen(1);
}

...which creates the global variable "fullscreen" and then checks if F4 is clicked and if so changes the window to fullscreen and sets the variable "fullscreen" to true which should stop the previous code from running and setting it back to windowed.

Instead of pressing F4 and getting a fullscreen window nothing happens and it is stuck in windowed mode. I have no idea what I'm doing wrong as I've looked through the manual and tested that replacing the first code with just global.fullscreen = true; makes it full screen (which it does) so if anyone could help and explain why this doesn't work and how to fix it please help.
 

Amon

Member
Code:
if ( keyboard_check_pressed(vk_f4))
{
    global.fullscreen = !global.fullscreen;
}

if ( global.fullscreen )
{
    window_set_fullscreen(true);
}else if ( !global.fullscreen )
{
    window_set_fullscreen(false);
}
 
Last edited:

O.Stogden

Member
Make sure you have "Allow Fullscreen Switching" enabled in your Game Options, as well as "Allow Window Resizing".
 

Redcakes

Member
Code:
if ( keyboard_check_pressed(vk_f4))
{
    global.fullscreen = !global.fullscreen;
}

if ( global.fullscreen )
{
    window_set_fullscreen(true);
}else if ( !global.fullscreen )
{
    window_set_fullscreen(false);
}
I can't seem to get this working.
 
Strange, as I see, your code should work just fine...
Maybe instead of setting global.fullscreen to !global.fullscreen, you can try this:

GML:
if keyboard_check_pressed(vk_f4)
{
    if global.fullscreen == false
        global.fullscreen = true;
    else
        global.fullscreen = false;  
}
 
S

Sam (Deleted User)

Guest
Make sure you have "Allow Fullscreen Switching" enabled in your Game Options, as well as "Allow Window Resizing".
Those aren't relevent.

I'd just do


if (keyboard_check_pressed(vk_f4)) { window_set_fullscreen(!window_get_fullscreen())
}

Why are you changing the window size at all when fullscreen will naturally do that anyway?
 
Last edited by a moderator:
I forgot to ask... In what event of your persistant object are you setting global.fullscreen to false?
You should put it in events that run only once, like "create", "game start" or "room start".
If it's inside a step event, it's constantly setting it to false every single frame. If that's the case, that's why you aren't being abble to change it.
 
S

Sam (Deleted User)

Guest
What's the point of storing fullscreen state in a global variable when you can just use window_get_fullscreen()?
 
What's the point of storing fullscreen state in a global variable when you can just use window_get_fullscreen()?
You can do that, but instead of using game maker's built in fullscreen toggle, some people prefer to set the window to borderless and changing it's resolution to the display size. Doing that fixed a problem I had with Vsync in GMS 1.4. Idk how that works on GMS 2+...
But I agree, the way it's used in this code is redundant.
I would suggest also to not use 2 different persistant objects, one should be enough to handle it, without setting the variable to global.
 
S

Sam (Deleted User)

Guest
You can do that, but instead of using game maker's built in fullscreen toggle, some people prefer to set the window to borderless and changing it's resolution to the display size. Doing that fixed a problem I had with Vsync in GMS 1.4. Idk how that works on GMS 2+...
But I agree, the way it's used in this code is redundant.
I would suggest also to not use 2 different persistant objects, one should be enough to handle it, without setting the variable to global.
Ah, I didn't realise they were doing that. Makes sense!

Back to the OP, not sure if this helps at all, but you might find this interesting:

Edit: sorry I'm not all there mentally, have covid.
 

Redcakes

Member
I forgot to ask... In what event of your persistant object are you setting global.fullscreen to false?
You should put it in events that run only once, like "create", "game start" or "room start".
If it's inside a step event, it's constantly setting it to false every single frame. If that's the case, that's why you aren't being abble to change it.
Yeah that was it. Spent quite a long time trying to figure it out but I just needed to move the check for F4 code from being inside a create event to a step event. Sorry about that, not sure why I had it there in the first place. Thanks for the help!
 
Top