0
\$\begingroup\$

I have oController as the first object to run when the game is opened. In oController's Game Start event I have the following code:

ini_open(working_directory + "SavedScores.ini");
var highscores = ini_read_real("Highscores", "Score", 0);
ini_close();

global.LastScore = highscores;

When the player has gotten their score, I use this code to save it:

if global.gameOver {
    
    if global.LastScore == 0 {
        global.LastScore = global.currentScore;
        
        ini_open(working_directory + "SavedScores.ini");
        ini_write_real("Highscores", "Score", global.LastScore);
        ini_close();
    } else {
        if global.currentScore > global.LastScore {
            global.LastScore = global.currentScore;
            
            ini_open(working_directory + "SavedScores.ini");
            ini_write_real("Highscores", "Score", global.LastScore);
            ini_close();
        }
    }
}

Whenever I relaunch the game on my phone, it won't load the score I got when I previously launched the game. Idk why it's not saving?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

I load the file in my player's creation event and it has solved my problem. :)

Put this in your controller object create event:

//Create save directory
global.dir = working_directory+"/Saves/"

I ran this code in the player create event:

if (file_exists(global.dir + "Score.ini")) {
    ini_open(global.dir + "Score.ini");
    global.LastScore = ini_read_real("Highscores", "Score", 0);
    ini_close();
}
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .