I've tried to use the save/load example that comes with gamemaker. It saves the character but not the room, the health or the keys and I dont know where to go from here the tutorial uses a .ini and a .txt but to be honest from what i can see the .ini is for saving global variables and the .txt is for saving and loading game objects. The character loads correctly but the keys collected keep resetting, the health returns to full and the room stays on the start screen could anyone advise what im doing wrong ? I can't seem to get passed this road block.
The code im using is:
//Initialise all the global variables
//Open the ini file for reading
ini_open("Save.ini");
//General Vars
global.hp = ini_read_real("Health", "hp", 100);
global.dest_room = ini_read_real("dest_room", "room", dest_room);
//Saving Keys
global.keyUp[0] = ini_read_real("keyUp", "0", keyUp);
global.keyLeft[1] = ini_read_real("keyLeft", "1", keyLeft);
global.keyDown[2] = ini_read_real("keyDown", "2", keyDown);
global.keyRight[3] = ini_read_real("keyRight", "3", keyRight);
global.keyBoss[4] = ini_read_real("keyBoss", "4", keyBoss);
//Close the ini file
ini_close();
The save code i use:
L-key press:
if !instance_exists(obj_Hero_Walk)
{
var file, str, str_pos, str_temp, val, num;
file = file_text_open_read("level.txt");
if file != -1
{
str = file_text_read_string(file);
file_text_readln(file);
str_pos = 1;
num = 0;
str_temp = "";
while(str_pos < string_length(str))
{
while (string_char_at(str, str_pos) != "|")
{
str_temp += string_char_at(str, str_pos);
str_pos += 1;
}
val[num] = real(str_temp);
str_pos += 1;
num += 1;
str_temp = "";
}
instance_create(val[0], val[1], obj_Hero_Walk);
str = file_text_read_string(file);
file_text_readln(file);
str_temp = "";
num = 0;
str_pos = 1;
while(str_pos < string_length(str))
{
while (string_char_at(str, str_pos) != "|")
{
str_temp += string_char_at(str, str_pos);
str_pos += 1;
}
val[num] = real(str_temp);
str_temp = "";
str_pos += 1;
num += 1;
if num = 2
{
num = 0;
instance_create(val[0], val[1], obj_Inventory);
}
}
file_text_close(file);
}
}
S-key press:
var file, str;
//Open file for writing
file = file_text_open_write("Level.txt");
//Create player string
str = string(obj_Hero_Walk.x) + "|" + string(obj_Hero_Walk.y) + "|";
//Write player string and go to a new line
file_text_write_string(file, str);
file_text_writeln(file);
//Reset string var
str = "";
//Write wall objects to file
with (obj_Inventory)
{
str += string(x) + "|" + string(y) + "|";
}
//Write string with wall information to file and start a new line
file_text_write_string(file, str);
file_text_writeln(file);
//Reset string var
str = "";
file_text_close(file);
not sure if this helps anyone see what I'm doing wrong.
Thanks in advance