In the following example, I show you how to load numbers from an .ini file, determine if the current score is higher than any of the high scores, and then rewrite the .ini file accordingly.
To start with, create the ini file. To do so, open up Notepad and save it as "name.ini". In the following example, I named the file "dum.ini"
You can set the .ini up as such:
[highscores]
score1 = 0
score2 = 0
score3 = 0
score4 = 0
score5 = 0
What you have just done is created a file with 5 variables, each capable of holding high scores. Score1 will hold the highest, score2 will hold the second highest, etc, etc.
NOTE THAT THE INI MUST BE IN THE SAME FOLDER AS THE GAME.The following will require you to use GML, but I've set it up so that you can just
copy/paste the code into a control object.
In the Create Event:
ini_open("dum.ini")//opens the .ini file for the data to be read
score_grid=ds_grid_create(1,5)//creates a data grid that holds the values of the high scores
ds_grid_set(score_grid,0,0,ini_read_real('highscores','score1',''))//sets the values of the datagrid
ds_grid_set(score_grid,0,1,ini_read_real('highscores','score2',''))
ds_grid_set(score_grid,0,2,ini_read_real('highscores','score3',''))
ds_grid_set(score_grid,0,3,ini_read_real('highscores','score4',''))
ds_grid_set(score_grid,0,4,ini_read_real('highscores','score5',''))
ini_close()//close the .ini; this is important
game_score=0//the current players score
Put this code when the round has ended.
//sets up a while loop that checks the value of the current score with every single one of the high scores.
a=0 //the current ranking of the score being checked. it starts at 0 because data grid numbering starts at 0
while a<5 //while a<the number of items in the data grid
{
if game_score>ds_grid_get(score_grid,0,a)//if the score is higher than this number
{
b=4
//this code slides down all the values of the high scores. so if your score is
//the new highest score, score 5 is set to score 4, score 4 is set to score 3, etc.
while b>=a
{
ds_grid_set(score_grid,0,b,ds_grid_get(score_grid,0,b-1))
b-=1
if b=0
break;//if you've run through all the numbers, QUIT
}
ds_grid_set(score_grid,0,a,game_score)
break;//if you've set the new score, QUIT
}
a+=1
}
ini_open("dum.ini")//WRITE THE NEW VALUES TO INI FILE
score1=ini_write_real('highscores','score1',ds_grid_get(score_grid,0,0))
score2=ini_write_real('highscores','score2',ds_grid_get(score_grid,0,1))
score3=ini_write_real('highscores','score3',ds_grid_get(score_grid,0,2))
score4=ini_write_real('highscores','score4',ds_grid_get(score_grid,0,3))
score5=ini_write_real('highscores','score5',ds_grid_get(score_grid,0,4))
ini_close()
Assuming you want to draw it, put this in the Draw Event.
i=0
while i<5
{
draw_text(x,y+20*i,ds_grid_get(score_grid,0,i))
i+=1
}
Have fun!