How do I save the player progress in a level progressing game in gamemaker

44 views Asked by At

my game in gamemaker consists of various rooms which are levels and you go on progressing, so imagine im in level 7, and I leave the game, it obviously goes back to room 1, im using the coding language of gamemaker btw.Also the only thing I have to save is just the level im in, I dont want to save any coins or smth!

Does anyone know how to stop and save the game to later on go back to it?

Thank you so much in advance!

1

There are 1 answers

0
Steven On

There are multiple ways to handle a saving method.

For example, one is to create a file and store the level variable there, using file_text_open_write.

var file;
file = file_text_open_write(working_directory + "level.txt");
file_text_write_string(file, level_data);
file_text_close(file);

Then, let the program read the file when opening the game to get the level data from it. Using file_text_open_read

var file = file_text_open_read(working_directory + "hiscore.txt");
for (var i = 0; i < 10; ++i;)
{
    scr[i] = file_text_read_real(file);
    file_text_readln(file);
    scr_name[i] = file_text_read_string(file);
    file_text_readln(file);
}
file_text_close(file);

Source for more information: https://manual.yoyogames.com/GameMaker_Language/GML_Reference/File_Handling/Text_Files/file_text_open_write.htm
and https://manual.yoyogames.com/GameMaker_Language/GML_Reference/File_Handling/Text_Files/file_text_read_string.htm