• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 Looks like I can't load save data, not sure why

My GameMaker version is 2.2.4.474.

I've made scripts for saving and loading, but nothing happens when I try to load a save. I'm not sure if the issue is in my save or load script. I'm new to Game Maker, so I don't know, maybe the solution's really simple.
I'm saving data for two maps - "Control_Mode_Map" holds the control setting that the player selected, and "Progress_Map" holds a simple number value for how many levels are beaten. Then I'm saving those maps into a single one I call the "Packet," and that becomes the string for my save file.

Here's my script for saving:
Code:
var Map = argument[0];
var Space = argument[1];
var Value = argument[2];


if !file_exists ("save.sav") {
    //First, create the Packet
    var Packet = ds_map_create();
    //Second, create the necessary maps and put them into the Packet
    var Control_Mode_Map = ds_map_create();
    ds_map_add_map (Packet, "Control_Mode_Map", Control_Mode_Map);
    var Progress_Map = ds_map_create();
    ds_map_add_map (Packet, "Progress_Map", Progress_Map);
    //Third, put stuff into the maps
    ds_map_add (Control_Mode_Map, "Control_Mode_Space", Control_Mode);
    ds_map_add (Progress_Map, "Progress_Space", Progress);
}

if file_exists ("save.sav") {
    //First, reopen the Packet
    var Packet = Get_String_From_File ("save.sav");
    //Second, define the correct map
    var Reloaded_Map = Packet [? Map];
    //Third, overwrite the correct value in that map
    ds_map_replace (Reloaded_Map, Space, Value);
}

//Encode the Packet into a string
var String = json_encode (Packet);
//Save the string to the file
var Buffer = buffer_create (string_byte_length (String) +1, buffer_fixed, 1);
buffer_write (Buffer, buffer_string, String);
buffer_save (Buffer, "save.sav");
buffer_delete (Buffer);
//Destroy the Packet
ds_map_destroy (Packet);

Here's my script for loading:
Code:
Map = argument[0]
Space = argument[1]
Value = argument[2]

if file_exists ("save.sav") {
    var Packet = Get_String_From_File ("save.sav");
    var ReloadedMap = Packet [? Map]
    var ReloadedSpace = ReloadedMap [? Space];
    Value = ReloadedSpace;
    ds_map_destroy (Packet);
}
And then there's one more script I was calling in the last two: "Get_String_From_File." Here's what that one looks like:
Code:
var File = argument[0];

var Buffer = buffer_load (File);
var String = buffer_read (Buffer, buffer_string);
buffer_delete (Buffer);

var JSON = json_decode (String);
return JSON;
I hope my code's easy to follow. Thank you, I'll really appreciate any help.
 
Top