K
King Gryzz
Guest
I have a problem where the ini files dont load properly. eg: if i get a score of 150 and type my name as "asd", and when I go to my ini file, it says asd and 150 however, when I re-open my game, the score isn't loaded and the ini file doesnt show asd or 150 anymore
Code that involves the ini file:
some room containing code
Submit button
Code that involves the ini file:
some room containing code
Code:
creation code:
ini_open("Save.sav");
for(i = 0; i < 10; i++)
{
global.score_array[i, 0] = "unknown";
global.score_array[i, 1] = 0;
}
ini_close()
room_goto(Rm_Level_1);
Code:
left button event
if (can_click == true)
{
can_click = false;
//get a name from the user
name = get_string_async("Enter your name:", "");
get_name = false;
}
Code:
Asynchronous Dialogue event
//listen for async dialog event
var i_d = ds_map_find_value(async_load, "id");
//if the dialog is the one where we ask the player for a name
if i_d == name
{
if ds_map_find_value(async_load, "status")//if the user clicked ok
{
//Checks if string length is not 5 digits or somethig long
//if the name entered is not blank or long
if (string_length(ds_map_find_value(async_load, "result")) > 5 || ds_map_find_value(async_load, "result") == "")
{
//determine in what way as to dislay the correct error message.
if (string_length(ds_map_find_value(async_load, "result")) > 5)
{
show_message_async("Name too long");
//get_name = true;
name = get_string_async("Enter your name:", "AAA");
}
if (ds_map_find_value(async_load, "result") == "")
{
show_message_async("No name entered!");
//get_name = true;
name = get_string_async("Enter your name:", "AAA");
}
}//otherwise the input is correct and we proceed as usual if it is less than or equal to 5 characters AND not empty
//if the name entered is not blank or too long
else if (string_length(ds_map_find_value(async_load, "result")) <= 5 && ds_map_find_value(async_load, "result") != "")
{
//get the name entered
global.name = ds_map_find_value(async_load, "result");
//Opens Save.sav
ini_open("Save.sav")
for (i = 0; i<10; i++)
{
//fill the global scores array with values from the ini file. If no values are present, then fill with name = unknown and score = 0
global.score_array[i, 0] = ini_read_string(string(i), "Name", "unknown");
global.score_array[i, 1] = ini_read_real(string(i), "Score", 0);
}
ini_close();
//search for first spot where player's score is greater
for (i = 0; i<10; i++)
{
//if the player's score is greater than the spot in question
if (global.Score > global.score_array[i, 1])
{
//starting at the last element of the array, set each element to the one before it.
for (j = 9; j>i; j--)
{
global.score_array[j, 0] = global.score_array[j-1, 0];
global.score_array[j, 1] = global.score_array[j-1, 1];
}
//now set the space to that of this player
global.score_array[i, 0] = global.name;
global.score_array[i, 1] = global.Score;
break;
}
}
//now update ini with this new array
ini_open("Score.sav")
for (i = 0; i<10; i++)
{
ini_write_string(string(i), "Name", global.score_array[i, 0]);
ini_write_real(string(i), "Score", global.score_array[i, 1]);
}
//Finishes creating and saves written data
ini_close();
//go to the room where the high scores table is shown
room_goto(Rm_Highscore);
}
}
//If clicked cancel, go to the Main Menu
else
{
room_goto(Rm_Main_Menu);
}
}