NeoShade
Member
I'm playing around with building a high score table using ini files and I've come across something that I find a little strange. As I test the game, sometimes my ini file will end up ordered 0-9 and sometimes it will be ordered 9-0. This doesn't really affect the operation of the game, but I find it strange. I've posted my code below (this is currently just running out of a room creation code for testing purposes) so can somebody tell me why this might be happening?
Code:
randomise();
// Initialise the Ini File
if (file_exists("scores.ini") == false)
{
ini_open("scores.ini");
{
ini_write_string("HS", "hsName0", "Name0");
ini_write_real("HS", "hsScore0", 10000);
ini_write_string("HS", "hsName1", "Name1");
ini_write_real("HS", "hsScore1", 9000);
ini_write_string("HS", "hsName2", "Name2");
ini_write_real("HS", "hsScore2", 8000);
ini_write_string("HS", "hsName3", "Name3");
ini_write_real("HS", "hsScore3", 7000);
ini_write_string("HS", "hsName4", "Name4");
ini_write_real("HS", "hsScore4", 6000);
ini_write_string("HS", "hsName5", "Name5");
ini_write_real("HS", "hsScore5", 5000);
ini_write_string("HS", "hsName6", "Name6");
ini_write_real("HS", "hsScore6", 4000);
ini_write_string("HS", "hsName7", "Name7");
ini_write_real("HS", "hsScore7", 3000);
ini_write_string("HS", "hsName8", "Name8");
ini_write_real("HS", "hsScore8", 2000);
ini_write_string("HS", "hsName9", "Name9");
ini_write_real("HS", "hsScore9", 1000);
}
ini_close();
}
// Generate a Test Case
myscore = irandom(100)*100;
myname = "Test";
show_message(string(myscore));
// Create a Grid
grid = ds_grid_create(2,11);
// Read the Ini File into the Grid
ini_open("scores.ini");
{
var i = 0;
repeat(10)
{
ds_grid_add(grid, 0, i, ini_read_string("HS", "hsName"+string(i), ""));
ds_grid_add(grid, 1, i, ini_read_real("HS", "hsScore"+string(i), 0));
i++;
}
}
ini_close();
// Add current score to the Grid
ds_grid_add(grid, 0, 10, myname);
ds_grid_add(grid, 1, 10, myscore);
// Sort the Grid
ds_grid_sort(grid, 1, false);
// Write the Grid back to the Ini File
ini_open("scores.ini");
{
var i = 0;
repeat(10)
{
ini_write_string("HS", "hsName"+string(i), ds_grid_get(grid, 0, i));
ini_write_real("HS", "hsScore"+string(i), ds_grid_get(grid, 1, i));
i++;
}
}
ini_close();