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

Remembering the state of changing the display mode of the game after quitting the game

sensodyne

Member
hi everyone,

I used the tutorial and used this solution in my game to switch the game from full screen to windowed mode while keeping the aspect ratio and back again.


The author described it very nicely in his tutorial, it works very well
Remembering the display mode of the game works until I quit the game

but I have one question ... I don't know how to make the screen change state remembered also after quitting the game completely
to put it more clearly, so that it remembers the screen save when I quit the game ..

my full code looks like this

obj_display_screen - this object is perssistent and is located in the first room of the game

create

GML:
ideal_width = 0;
ideal_height = 480;

aspect_ratio = display_get_width()/display_get_height();
//aspect_ratio = clamp(aspect_ratio,16/9, 21/9);

ideal_width = round(ideal_height * aspect_ratio);

//Check if odd number
if (ideal_width & 1) {
    ideal_width ++;
}

for (var i=2; i <= room_last; i++) {
    if (room_exists(i)) {
    
      
        view_wview[0] = ideal_width;
        view_hview[0] = ideal_height;
      
        view_wport[0] = ideal_width;
        view_hport[0] = ideal_height;
    }
}


surface_resize(application_surface, ideal_width, ideal_height);

window_set_size(ideal_width,ideal_height);



room_goto(room_next(room));

obj_menu

create

GML:
options=ds_list_create()
options[|0]=Controlls
options[|1]=Sound
options[|3]=Back

if (window_get_fullscreen()) {
options[|2]=Fullscreen
} else {
options[|2]=Windowed
}


animation_speed=room_speed/2
for(var i=0; i<ds_list_size(options); i++) {
    animation[i]=0
}



selected=0

step

GML:
if(keyboard_check_pressed(vk_enter))   {
    if(selected=0) {
        room_goto(room_controls)
    } else if(selected=1) {
        room_goto(room_sounds)
    } else if(selected=2) {
    
   window_set_fullscreen(!window_get_fullscreen());
   options[|2]=Fullscreen;

     if (!window_get_fullscreen()) {

    window_set_size(obj_display_screen.ideal_width, obj_display_screen.ideal_height);
    options[|2]=Windowed;

   }


    } else if(selected=3) {
        room_goto(roo_menu_game)
    }
}
 
Last edited:

TsukaYuriko

☄️
Forum Staff
Moderator
Take a look at the file functions in the manual. You can save the state to a file, read it back and adapt as needed.
 

sensodyne

Member
Take a look at the file functions in the manual. You can save the state to a file, read it back and adapt as needed.
Yeah i guess i have to do that ..
the only question is which function should I use? should this function be used in the step event of the obj_menu object any of you have experience with this?
an example could be useful
 

TsukaYuriko

☄️
Forum Staff
Moderator
You seem to have an options menu already implemented, so my general idea was to save the value of selected to a file when you confirm the game options (or close the game, or whenever you want to save it). You can then read it back at game start and change the display mode accordingly.

The shortest way to write a number to a file involves file_text_open_write, file_text_write_real[/FONT] and file_text_close. Reading follows the same procedure, except with every write being replaced by read. You can check their manual pages for usage examples.
 

sensodyne

Member
You seem to have an options menu already implemented, so my general idea was to save the value of selected to a file when you confirm the game options (or close the game, or whenever you want to save it). You can then read it back at game start and change the display mode accordingly.

The shortest way to write a number to a file involves file_text_open_write, file_text_write_real[/FONT] and file_text_close. Reading follows the same procedure, except with every write being replaced by read. You can check their manual pages for usage examples.
Where is the best place to use this feature?
probably in the step event where I change the image display mode?

This manual, which you gave, is not readable ... it's hard for me to assemble something from it.
I want the game to remember the image settings after restarting the game when I quit the game.


That is, how I set the window mode option, then when I quit the game and restart it, it should start in window mode
and the opposite situation, when I choose full screen mode, after exiting the game and restarting the game it should start in full screen
 

TsukaYuriko

☄️
Forum Staff
Moderator
Probably at these times:

You seem to have an options menu already implemented, so my general idea was to save the value of selected to a file when you confirm the game options (or close the game, or whenever you want to save it). You can then read it back at game start and change the display mode accordingly.
When the first one happens is something you can answer better than me. The second one happens in the Game Start event of an instance of an object in the first room.
 

sensodyne

Member
Probably at these times:



When the first one happens is something you can answer better than me. The second one happens in the Game Start event of an instance of an object in the first room.
ie in the options menu save it to an ini file? And in the first room where the game starts to read these values? that's how I understood it

Ok if so that's good but is there any better documentation and preferably an example that i could use and implement in my code?
 

TsukaYuriko

☄️
Forum Staff
Moderator
Correct. Whether you want to use an ini file, a text file, a binary file... is up to you.

The manual I linked contains usage examples. I'm not sure why it's "not readable" to you, but you may be able to find a tutorial for file handling if the manual is not to your liking.
 

sensodyne

Member
Correct. Whether you want to use an ini file, a text file, a binary file... is up to you.

The manual I linked contains usage examples. I'm not sure why it's "not readable" to you, but you may be able to find a tutorial for file handling if the manual is not to your liking.
maybe that's why it is illegible for me, because I have no way to relate to. The first time I feel like this ... probably the second time I would know how to solve it ... it's nice as if there was a living example :)
 

FrostyCat

Redemption Seeker
Do you have anything else saved in your game, such as scores or names? If you do, I don't see what's so difficult about this. Instead of just saving and loading scores and names, just save and load scores and names AND screen dimensions.

If say you had INI code for saving the player's best score and the player's name:
GML:
ini_open(working_directory + "save.ini");
ini_write_string("user", "name", global.name);
ini_write_real("user", "best", global.bestPoints);
ini_close();
GML:
ini_open(working_directory + "save.ini");
global.name = ini_read_string("user", "name", "Player");
global.bestPoints = ini_read_real("user", "best", 0);
ini_close();
Then adding the screen's dimensions to that is just two more minor variations of the third line:
GML:
ini_open(working_directory + "save.ini");
ini_write_string("user", "name", global.name);
ini_write_real("user", "best", global.points);
ini_write_real("screen", "width", obj_display_screen.ideal_width);
ini_write_real("screen", "height", obj_display_screen.ideal_height);
ini_close();
GML:
ini_open(working_directory + "save.ini");
global.name = ini_read_string("user", "name", "Player");
global.bestPoints = ini_read_real("user", "best", 0);
obj_display_screen.ideal_width = ini_read_real("screen", "width", 1024);
obj_display_screen.ideal_height = ini_read_real("screen", "height", 768);
ini_close();
Anyone who genuinely understood what the original code was doing would have come up with this in no more than 10 seconds.

Don't waste time trying to learn context-specific stuff like "how to save an RPG inventory". Spend time learning context-independent things like "how to save numeric and string values". That's how a computer looks at information, and if you want to last in this line of work, you need to look at information the same way.
 
Top