W
Whirlpoolio
Guest
Hey!
I'm currently working on save and load but I've run into a problem... It saves the room and health etc. but not the enemies. So let's say you just cleared a level but stay in that room, then you quit and when you return there are all the enemies you just killed (What is happening). I want it so when you return they are dead - like they were (What I want).
This is my current save file script:
And load script:
Any help is appreciated!
I'm currently working on save and load but I've run into a problem... It saves the room and health etc. but not the enemies. So let's say you just cleared a level but stay in that room, then you quit and when you return there are all the enemies you just killed (What is happening). I want it so when you return they are dead - like they were (What I want).
This is my current save file script:
Code:
///scr_savegame();
// Make sure the player exists
if (!instance_exists(obj_player)) exit;
// Create the save data structure
var save_data = ds_map_create();
with (obj_player) {
save_data[? "room"] = room;
save_data[? "x"] = x;
save_data[? "y"] = y;
save_data[? "hp"] = hp;
save_data[? "maxhp"] = maxhp;
}
var save_string = json_encode(save_data);
ds_map_destroy(save_data);
save_string = base64_encode(save_string);
var file = file_text_open_write(working_directory + "save.txt");
file_text_write_string(file,save_string)
file_text_close(file);
Code:
///scr_loadgame();
var file = file_text_open_read(working_directory+"save.txt");
var save_string = file_text_read_string(file);
file_text_close(file);
save_string = base64_decode(save_string);
var save_data = json_decode(save_string);
global.rom = save_data[? "room"];
room_goto(global.rom);
with (obj_player) {
player_xstart = save_data[? "x"]
player_ystart = save_data[? "y"]
x = player_xstart;
y = player_ystart;
phy_position_x = player_xstart;
phy_position_y = player_ystart;
hp = save_data[? "hp"];
maxhp = save_data[? "maxhp"];
}
ds_map_destroy(save_data);