Steam Saving to Steam Cloud

Bee

Member
Hello wonderful people,

We're so close to launching our first game! But I'm trying to figure out how to save and load from Steam Cloud. Before, I was using ds_map_secure_save and load, but if I do that and save that file, it's encoded and doesn't get decoded. So I tried writing the map to an ini file this way (two methods, but one is commented out):
Code:
    ini_open("HSmap.ini");
    var t_string = ds_map_write(data);
    ini_write_string("SaveGame", "0", t_string);
    
    
    if (steam_is_cloud_enabled_for_account() == true && steam_is_cloud_enabled_for_app() == true) {
        show_debug_message("cloud enabled");
        //if (!steam_file_exists("HSSaveData.sav")) {
            //steam_file_write("HSSaveData.sav", data, ds_map_size(data));   
        //}
        steam_file_write_file("HSSaveData.sav", "HSmap.ini");
    }
    ini_close();
But it throws the following error:
Attempting to WriteValue for unsupported type -2147483648

The load code I wrote is:
Code:
//if (steam_file_exists("HSSaveData.sav")) {
    //var file = steam_file_read("HSSaveData.sav");
    //ini_open("HSmap.ini");
    //ini_write_string("SaveGame", "0", file);
    
    //var data = ini_read_string("SaveGame", "0", "-1");
    //ini_close();
}
I've never launched a game on Steam before and am pretty new at all this anyhow, so any help will be much appreciated.
 

Bee

Member
Okay I've done a lot of testing to narrow this problem down. I changed it from ini to text files, just in case. It's still throwing the error message but the data is saving right. Upon load, it's getting the keys from the map but all the associated values are undefined. So it's only half working which means it's not working at all lol. Any ideas?

Here's the code:

Code:
    t_string = ds_map_write(data);
    
    txtfile = file_text_open_write("HStext.sav");
    file_text_write_string(txtfile, t_string);
    file_text_close(txtfile);
    
    if (steam_is_cloud_enabled_for_account() == true && steam_is_cloud_enabled_for_app() == true) {
        show_debug_message("cloud enabled");
        steam_file_write_file("HSSaveData.sav", "HStext.sav");
    }
And loading:
Code:
    file = steam_file_read("HSSaveData.sav");
    data = ds_map_create();
    ds_map_read(data, file);
 

Bee

Member
Update! Instead of ds_map_write and ds_map_read I used json_encode and json_decode. And it worked! The error even went away. Yippee!
 
J

Jorge León

Guest
Can you share the code, please?
I'm struggling with the same issue and don't know that much :(
 
J

Jorge León

Guest
Can you share the code, please?
I'm struggling with the same issue and don't know that much :(
Don't worry, I found another way. If someone needs it in the future, to save I just used:

if (steam_file_exists("SteamDatos.sav")) steam_file_delete("SteamDatos.sav");
steam_file_write_file("SteamDatos.sav", "Datos.sav");

And for loading I used:

var file = steam_file_read("SteamDatos.sav");
ini_open_from_string(file);
//Here would be the transferring of data
ini_close();
 
J

Jorge León

Guest
@Jorge when do you call those scripts? When the game saves? Or when the game exit?
Sorry for the delay (I don't use to check the forum). My game does it everytime it saves (maybe, if you save too often or too much data, you would prefer to update the cloud only on certain cases/conditions)
 
Top