S
Sundog
Guest
I'm currently having trouble getting my load game script to work across all of my rooms. It's very odd and no matter how much I rack my brain I just can't seem to figure out what is going on! Technically everything is loading in fine except my inventory which I'm just using ds lists to create/save my inventory.
Let me start by saying right now I have three rooms aside from my pause rooms that the player can be in. That is "start_screen", "rm_one", and "rm_two".
If i were to save while in rm_two and then go to rm_one and load it from that room then it would work flawlessly; no issues there! Now If I try to load that exact same save file from the start_screen room it will load up the room fine however during the load script I notice it's no longer recognizing the data I saved into the text file as a DS list so It just completely gets skipped over!
Now if I were to save in rm_one and load from rm_two, no issues there. Then if I load that exact same save in rm_one from the start_screen that would also work! So it is very confusing, I don't understand what game makers disconnect is from the second room but its really frustrating!
I originally thought it may be a room persistence problem because I had some rooms I accidentally left persistent but it can't be, I turned those off and it still happens. The save script literally just does not recognize that they are ds lists when trying to load the inventory. It makes absolutely no sense!
Here's my save script if you need to take a look at it!
Also I'm using the JSON parsing library JSOnion to make life a little easier. If there have been known issues with this then maybe Ill try to figure out another way to save.
Let me start by saying right now I have three rooms aside from my pause rooms that the player can be in. That is "start_screen", "rm_one", and "rm_two".
If i were to save while in rm_two and then go to rm_one and load it from that room then it would work flawlessly; no issues there! Now If I try to load that exact same save file from the start_screen room it will load up the room fine however during the load script I notice it's no longer recognizing the data I saved into the text file as a DS list so It just completely gets skipped over!
Now if I were to save in rm_one and load from rm_two, no issues there. Then if I load that exact same save in rm_one from the start_screen that would also work! So it is very confusing, I don't understand what game makers disconnect is from the second room but its really frustrating!
I originally thought it may be a room persistence problem because I had some rooms I accidentally left persistent but it can't be, I turned those off and it still happens. The save script literally just does not recognize that they are ds lists when trying to load the inventory. It makes absolutely no sense!
Here's my save script if you need to take a look at it!
Also I'm using the JSON parsing library JSOnion to make life a little easier. If there have been known issues with this then maybe Ill try to figure out another way to save.
Code:
///scr_load_game(jso_map, file)
//Open the save content
if(file_exists(working_directory + "save.txt")){
var file = file_text_open_read(working_directory + "save.txt");
var file_contents = file_text_read_string(file);
file_text_close(file);
//save_string = base64_decode(save_string); //decode data back to json_encode format
var save_data = jso_decode_map(file_contents); //decode that data back into a ds_map
} else {
show_debug_message("No save file found!");
exit;
}
//Overwrite the rooms save
if(file_exists(working_directory + "rooms.txt") && jso_map_check(save_data, "rooms_map")){
file_delete(working_directory + "rooms.txt");
var rooms_map = jso_map_lookup(save_data, "rooms_map");
var json = jso_encode_map(rooms_map);
var file = file_text_open_write(working_directory + "rooms.txt");
file_text_write_string(file, json);
file_text_close(file);
}
//Clear all enemies in the room
if(instance_exists(obj_enemy_parent)){
instance_destroy(obj_enemy_parent);
}
//Clear all instances of items in the room
if(instance_exists(obj_item)){
instance_destroy(obj_item);
}
//Load the saved player stats
with(obj_player_stats) {
//Set the players saved position
player_xstart = jso_map_lookup(save_data, "player_data", "x");
player_ystart = jso_map_lookup(save_data, "player_data", "y");
if(instance_exists(obj_player)) {
obj_player.x = player_xstart;
obj_player.y = player_ystart;
obj_player.phy_position_x = player_xstart;
obj_player.phy_position_y = player_ystart;
} else {
instance_create(player_xstart, player_ystart, obj_player);
}
show_debug_message(instance_exists(obj_player));
//Set facing direction
obj_player.face = jso_map_lookup(save_data, "player_data", "face");
//Get the stats
hp = jso_map_lookup(save_data, "player_data", "hp");
maxhp = jso_map_lookup(save_data, "player_data", "maxhp");
stamina = jso_map_lookup(save_data, "player_data", "stamina");
maxstamina = jso_map_lookup(save_data, "player_data", "maxstamina");
expr = jso_map_lookup(save_data, "player_data", "expr");
maxexpr = jso_map_lookup(save_data, "player_data", "maxexpr");
level = jso_map_lookup(save_data, "player_data", "level");
atk = jso_map_lookup(save_data, "player_data", "atk");
mag_atk = jso_map_lookup(save_data, "player_data", "mag_atk");
phy_def = jso_map_lookup(save_data, "player_data", "phy_def");
mag_def = jso_map_lookup(save_data, "player_data", "mag_def");
}
//Load player Inventory
with(obj_player_inventory) {
var list = -1;
var inv_count = 0;
for(i = array_height_2d(inv)-1; i > -1; i--;) {
for(j = array_length_2d(inv, i)-1; j > -1; j--;) {
list = jso_map_lookup(save_data, "player_data", "inv_item" + string(inv_count));
show_debug_message("true/false = " + string(ds_exists(list, ds_type_list)))
if(ds_exists(list, ds_type_list)){
list[| 6] = jso_map_lookup(save_data, "player_data", "inv_stack" + string(inv_count));
inv[i, j] = list;
}
inv_count++;
}
}
row = jso_map_lookup(save_data, "player_data", "inv_row");
column = jso_map_lookup(save_data, "player_data", "inv_col");
}
//Load player equipment
with(obj_player_equipment) {
var old_weapon = weapon;
var old_armor = armor;
var old_ring = ring;
var old_neck = neck;
show_debug_message(weapon);
weapon = instance_create(0, 0, jso_map_lookup(save_data, "player_data", "weapon"));
armor = instance_create(0, 0, jso_map_lookup(save_data, "player_data", "armor"));
ring = instance_create(0, 0, jso_map_lookup(save_data, "player_data", "ring"));
neck = instance_create(0, 0, jso_map_lookup(save_data, "player_data", "neck"));
weapon.persistent = true;
armor.persistent = true;
ring.persistent = true;
neck.persistent = true;
instance_destroy(old_weapon);
instance_destroy(old_armor);
instance_destroy(old_ring);
instance_destroy(old_neck);
}
//Load new data for items
if(jso_map_check(save_data, "room_data", "item_count")) {
var len = jso_map_lookup(save_data, "room_data", "item_count");
var item_y = 0;
var item_x = 0;
var item_ind = -1;
for(i = len; i > -1; i--) {
if(jso_map_check(save_data, "room_data", "item_" + string(i))) {
item_ind = jso_map_lookup(save_data, "room_data", "item_" + string(i));
item_y = jso_map_lookup(save_data, "room_data", "item_y_" + string(i));
item_x = jso_map_lookup(save_data, "room_data", "item_x_" + string(i));
instance_create(item_x, item_y, item_ind);
}
}
}
//Load new data for enemies
if(jso_map_check(save_data, "room_data", "enemy_count")) {
var len = jso_map_lookup(save_data, "room_data", "enemy_count");
var enemy_y = 0;
var enemy_x = 0;
var enemy_ind = -1;
for(i = 0; i < len; i++) {
if(jso_map_check(save_data, "room_data", "enemy_" + string(i))) {
enemy_ind = jso_map_lookup(save_data, "room_data", "enemy_" + string(i));
enemy_y = jso_map_lookup(save_data, "room_data", "enemy_y_" + string(i));
enemy_x = jso_map_lookup(save_data, "room_data", "enemy_x_" + string(i));
instance_create(enemy_x, enemy_y, enemy_ind);
}
}
}
jso_cleanup_map(save_data);
show_message("Loaded game!");