Hi people, new to the GMS file system here, and I met a problem with saving my game.
Basically, I have 3 files I need to save, dnahs rnahs and proteinhs. I have a high score object that was created at the start of the game, and the create event looks like this:
The game end event looks like this:
I will not include all of my codes here because they are too long, but the global variables worked nicely without a problem when I was playing through my game. However, when I close the game and try to play it again, the global variables just all return to 0. Can someone please help?
Basically, I have 3 files I need to save, dnahs rnahs and proteinhs. I have a high score object that was created at the start of the game, and the create event looks like this:
GML:
globalvar dnahs;
globalvar rnahs;
globalvar proteinhs;
dnahs = 0;
rnahs = 0;
proteinhs = 0;
#macro DNAHS "dna.sav"
#macro RNAHS "rna.sav"
#macro PROTEINHS "protein.sav"
if (file_exists(DNAHS))
{
var file0 = file_text_open_read(DNAHS);
var target0 = file_text_read_real(file0);
file_text_close(file0);
dnahs = target0;
}
if (file_exists(RNAHS))
{
var file1 = file_text_open_read(RNAHS);
var target1 = file_text_read_real(file1);
file_text_close(file1);
rnahs = target1;
}
if (file_exists(PROTEINHS))
{
var file2 = file_text_open_read(PROTEINHS);
var target2 = file_text_read_real(file2);
file_text_close(file2);
dnahs = target2;
}
GML:
var file0 = file_text_open_write(DNAHS);
file_text_write_real(file0,dnahs);
file_text_close(file0);
var file1 = file_text_open_write(RNAHS);
file_text_write_real(file1,rnahs);
file_text_close(file1);
var file2 = file_text_open_write(PROTEINHS);
file_text_write_real(file2,proteinhs);
file_text_close(file2);