K
kbuell5
Guest
This is my first forum post here, so if I neglect to put any important code please tell me and I'll try to include what's needed.
I'm working in GameMaker v1.4.1804. I've followed Shaun Spalding's JSON based save/load tutorials and I'm run into a problem. Whenever I load my game, when I go to the room that I last saved in, the player object spawns in a fixed location every time that is not the x,y values I stored when I saved. No matter what value I've actually saved to my JSON file, the player spawns in the same wrong place every time. I've used debug messages and made sure that the values I'm saving are saving properly. There just seems to be something wrong with the actual loading process, or possibly something happening when the room starts, although they don't have any creation code. I'm loading from a menu room that's separate from the room I've saved in.
Here is my code for my loading script (I've put it all because I don't know how much to include):
I'm almost positive the bug doesn't have anything to do with my save script. Everything else saves and loads fine. My character object is persistent. I don't have an instance in it placed in the room creator menu thing, so it's not that that's overriding it. I've tried so many things and I'm at a loss. I have a feeling the solution is simple and I'm missing it.
Here's what it looks like when I load.
I'm working in GameMaker v1.4.1804. I've followed Shaun Spalding's JSON based save/load tutorials and I'm run into a problem. Whenever I load my game, when I go to the room that I last saved in, the player object spawns in a fixed location every time that is not the x,y values I stored when I saved. No matter what value I've actually saved to my JSON file, the player spawns in the same wrong place every time. I've used debug messages and made sure that the values I'm saving are saving properly. There just seems to be something wrong with the actual loading process, or possibly something happening when the room starts, although they don't have any creation code. I'm loading from a menu room that's separate from the room I've saved in.
Here is my code for my loading script (I've put it all because I don't know how much to include):
GML:
with (obj_player) instance_destroy();
var party_grid = global.ds_party;
if (file_exists("savedgame.sav"))
{
var _wrapper = scr_loadJSONFromFile("savedgame.sav");
var _list = _wrapper[? "ROOT"];
for (var i = 0; i < ds_list_size(_list); i++)
{
var _map = _list[| i];
var _obj = _map[? "obj"];
with (instance_create(0,0,asset_get_index(_obj)))
{
room_goto(_map[? "room"]);
x = _map[? "x"];
y = _map[? "y"];
show_debug_message("X,Y Coords LOADED as: " + string(_map[? "x"]) + ", " + string(_map[? "y"]));
show_debug_message("Player X,Y: " + string(x) + ", " + string(y));
party_grid[# 0,0] = _map[? "name"];
party_grid[# 1,0] = _map[? "hp"];
party_grid[# 2,0] = _map[? "hpMax"];
party_grid[# 3,0] = _map[? "xp"];
party_grid[# 4,0] = _map[? "xpMax"];
party_grid[# 5,0] = _map[? "lvl"];
party_grid[# 6,0] = _map[? "status"];
party_grid[# 7,0] = _map[? "inParty"];
global.money = _map[? "money"];
global.playerDown = _map[? "downSprite"];
global.playerLeft = _map[? "leftSprite"];
global.playerRight = _map[? "rightSprite"];
global.playerUp = _map[? "upSprite"];
image_index = _map[? "image_index"];
}
}
show_debug_message("Player x,y (2nd time): " + string(x) + ", " + string(y));
ds_map_destroy(_wrapper);
show_debug_message("Game Loaded");
}
Here's what it looks like when I load.