S
saltysquid
Guest
so I'm making a small game and trying to save high scores but for some reason when I try to run it I get an error saying the file to save high scores isn't open for writing even doe I opened it the line before
scrFile = working_directory + "scores.txt"
// Creates a points variable any object can use
global.points = 0;
// Checks if a scores file exists, if so stores the saved scores, if not makes one and fills it with zeros
if(file_exists(scrFile)) {
file_text_open_read(scrFile);
global.score0 = file_text_read_real(scrFile);
file_text_readln(scrFile);
global.score1 = file_text_read_real(scrFile);
file_text_readln(scrFile);
global.score2 = file_text_readln(scrFile);
file_text_close(scrFile);
} else if(!file_exists(scrFile)) {
file_text_open_write(scrFile);
file_text_write_real(scrFile, 0);
file_text_writeln(scrFile);
global.score0 = 0;
file_text_write_real(scrFile, 0);
file_text_writeln(scrFile);
global.score1 = 0;
file_text_write_real(scrFile, 0);
file_text_writeln(scrFile);
global.score2 = 0;
file_text_close(scrFile)
}
the red part is what its complaining about but I assume if it wasnt already having issue there it would have them with the next times it tried to write something in
the scrFile variable is just to avoid having to put the same thing in so many times
I know this probably isn't the most efficient way to do it but I don't really care
scrFile = working_directory + "scores.txt"
// Creates a points variable any object can use
global.points = 0;
// Checks if a scores file exists, if so stores the saved scores, if not makes one and fills it with zeros
if(file_exists(scrFile)) {
file_text_open_read(scrFile);
global.score0 = file_text_read_real(scrFile);
file_text_readln(scrFile);
global.score1 = file_text_read_real(scrFile);
file_text_readln(scrFile);
global.score2 = file_text_readln(scrFile);
file_text_close(scrFile);
} else if(!file_exists(scrFile)) {
file_text_open_write(scrFile);
file_text_write_real(scrFile, 0);
file_text_writeln(scrFile);
global.score0 = 0;
file_text_write_real(scrFile, 0);
file_text_writeln(scrFile);
global.score1 = 0;
file_text_write_real(scrFile, 0);
file_text_writeln(scrFile);
global.score2 = 0;
file_text_close(scrFile)
}
the red part is what its complaining about but I assume if it wasnt already having issue there it would have them with the next times it tried to write something in
the scrFile variable is just to avoid having to put the same thing in so many times
I know this probably isn't the most efficient way to do it but I don't really care