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

GML Saving a variable [High Score]

A

Ambition13z

Guest
I am trying to make a simple High Score that is saved even after closing the game (its an asteroids type game). Right now when the player ship gets blown up, you transfer to the High Score room. In there you will see two scores, where one says what your final Score was. The other is the high score. I was trying to figure out how to save the high score only. here is my code for drawing the high score:

//Score Draw
draw_set_color(c_white);
draw_set_halign(fa_center);
draw_set_valign(fa_top);
draw_set_font(fnt_mid);
draw_text(300,200,"Final Score: " + string(global.points));
if (global.points > global.final)
{
global.final = global.points;
draw_text(300,270,"High Score: " + string(global.final));
}
else
{
draw_text(300,270,"High Score: " + string(global.final));
}


Everything shows up fine, except for the final score always being the high score (due to the high score never saving).
 

Perseus

Not Medusa
Forum Staff
Moderator
Write the final score to an INI file if it's larger than the last high score already in the file.

Create:
Code:
ini_open("data.ini");
last = ini_read_real("data", "highscore", 0);
if (globlal.points > last) {
    ini_write_real("data", "highscore", global.points);
    last = global.points;
}
ini_close();
In the Draw event, draw global.points as the current final score and last as the high score.
 
C

Comik25

Guest
Hi @Ambition13z, can you share the last codes " to save high score" pls?
 

FrostyCat

Redemption Seeker
Hi @Ambition13z, can you share the last codes " to save high score" pls?
Before you make any more replies, check the timestamps before you reply. This is a 3-year-old topic, and the account you are trying to get a response from is clearly marked as deactivated. Besides, post #2 on this topic already has the code for saving a single high score.
 
Top