• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM How to save dead enemies? [DS MAP]

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:
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);
And load script:
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);
Any help is appreciated!
 
M

maratae

Guest
If you have the enemies hold their, let's say, x and y at creation time, you can save a list of the coords of dead enemies.
On room start, make the enemies check that list. If their coords are on the list, instance_destroy(id, false)
 
W

Whirlpoolio

Guest
Ah ok! So could you give me some example code because would I do something like
Code:
if (hp<=0) {
    ds_map_add_list(save_data,"dead",dead)
}
Or nah?
 
Top