ZyKro
Member
I am trying to do a save system for a game I am working on and I'm not sure how to go about it. I heard data structures are very useful, but I am having trouble trying to make it work.
I am using ds maps, but I don't know if it is the best way to go for me for what I am saving. I want to save information about a level, mainly when the player completes it, the next level is unlocked. I want to save data where it can't be modified easily. There's only 2 things I want to save at the moment, but it should get larger.
The level information doesn't seem to be saving because when I try to go to level 2, it is locked still, but I am able to go to it after completing stage 1 when I continue to next level (without exiting the room).
Checker Object (persistent)
Stage Controller Object
Player Object Step Event (partial)
global.stage shouldn't be the problem because it was created in the create event of another object.
I appreciate any help.
I am using ds maps, but I don't know if it is the best way to go for me for what I am saving. I want to save information about a level, mainly when the player completes it, the next level is unlocked. I want to save data where it can't be modified easily. There's only 2 things I want to save at the moment, but it should get larger.
The level information doesn't seem to be saving because when I try to go to level 2, it is locked still, but I am able to go to it after completing stage 1 when I continue to next level (without exiting the room).
Checker Object (persistent)
Code:
/// obj_checker create
save_data = ds_map_create();
filename = "Savedata.sav";
ds_map_add(save_data, "stagenum2", false);
ds_map_add(save_data, "stagenum3", false);
if (file_exists(filename)) {
ds_map_destroy(save_data);
save_data = ds_map_secure_load(filename);
}
Code:
///Create Event
stagenum[0] = true;
stagenum[1] = false;
stagenum[2] = false;
var _stage2, _stage3;
_stage2 = ds_map_find_value(obj_checker.save_data, "stagenum2");
_stage3 = ds_map_find_value(obj_checker.save_data, "stagenum3");
scr_check_undefined(_stage2, stagenum[1]);
scr_check_undefined(_stage2, stagenum[2]);
Code:
///Step
switch (global.stage) {
case 1:
if (global.enemy_count >= 25) {
ds_map_replace(obj_checker.save_data, "stagenum2", true);
ds_map_secure_save(obj_checker.save_data, obj_checker.filename);
instance_change(obj_player_end, true);
}
break;
case 2:
if (global.enemy_count >= 50) {
ds_map_replace(obj_checker.save_data, "stagenum3", true);
ds_map_secure_save(obj_checker.save_data, obj_checker.filename);
instance_change(obj_player_end, true);
}
break;
case 3:
if (global.enemy_count >= 75) {
//do something
instance_change(obj_player_end, true);
}
break;
}
I appreciate any help.