Ok I would differ between the displayed highscore and the internal highscore which is sorted etc.
The displayed-highscore would be made just out of one string array aka. text object.
Example for a highscore with ten entries:
Code:
text highscore_display
{
pos_x = x;
pos_y = y;
layer = z;
font = my_font;
strings = 10;
}
The interal highscore would consist out of a string array and a numeric array:
Code:
var hs_points[10];
text hs_names { strings = 10; }
What you save on the harddisk: the point array and the name strings:
Code:
function save_highscore
{
var i = 0;
var fhandle_1;
var fhandle_2;
fhandle_1 = file_open_write("hs_points.txt");
fhandle_2 = file_open_write("hs_names.txt");
while(i < 10)
{
file_var_write(fhandle_1,hs_points[i]);
file_str_write(fhandle_2,hs_names.string[i]);
i += 1;
}
file_close(fhandle_1);
file_close(fhandle_2);
}
Loading works the same way but with file_var/str_read
Sorting the highscore:
This happens when you add a new highscore entry.
Basicly you have to compare the new entry value with the current entry values and then have to do a copying down, so that the last entry drops out of the list, or the entry does not get in, because its value is < the lowest highscore entry.
Ok, so lets do a simple function for this:
Code:
function hs_add_entry(_value,_name)
{
var i = 0;
var k = 1;
while(k)
{
if(hs_points[i] < _value || i = 9)
{
k = 0;
}
else { i+= 1; }
}
//Now we know where to place the new entry in the list
//But we first have to scroll the other entrys to the bottom
k = 9;
while(k > i)
{
hs_points[k] = hs_points[k-1];
str_cpy(hs_names.string[k],hs_names.string[k-1]);
k -= 1;
}
hs_points[i] = _value;
str_cpy(hs_names.string[i],_name);
}
//How to call the function:
hs_add_entry(var,string);
example:
hs_add_entry(999,"Fiskekona");
Ok now the displaying of the highscore:
This function will make a string out of the interal arrays and save it to that text object which you then can display:
Code:
string temp1_str;
string entry_str;
function hs_show()
{
var i = 0;
while(i < 10)
{
str_for_num(entry_str,i+1);
str_cat(entry_str,". ");
str_cat(entry_str,hs_names.string[i]);
str_for_num(temp1_str,hs_points[i]);
str_cat(entry_str," ");
str_cat(entry_str,temp1_str);
i += 1;
}
}
NOTE: None of this code has been tested by me, I wrote it all of my head how it _could_ work. No gurantee that it will.
But this should give you a slight idea how you could handle a highscore system.