• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

UWP Asynchronous Saving fine for Windows but not UWP

Previously I had an issue with some code for Asynchronous Saving which was fixed with one line. However I now have a new problem with the code

In Windows, the saving works normally with no issue and is working like nothing happened. On UWP however it's a different story. I made it so that I can manually cause a save by pressing F5. If I try this, the game will freeze for 1-2 seconds before returning to normal and after that nothing will happen if I try again. If the game does this automatically the game will fully freeze and no error message will be displayed. I followed the following article to create my saving code:
I'm targeting both Xbox and PC in UWP so if it doesn't work on my PC, my Xbox wont stand a chance.

When saving, my game uses 3 events. A Save script, A Load Script and a Asynchronous Load/Save event in a persistent object.
Here is the Save Script:
Code:
if !instance_exists(obj_cog_save)
{
    instance_create_depth(1770, 930, -100, obj_cog_save);
}

buffer_async_group_begin("Sentinel_Tank_Files");
buffer_async_group_option("showdialog",0);
buffer_async_group_option("Sentinel_Tank_Files","Sentinel_Tank_Files");   
buffer_async_group_option("Sentinel_Tank_Files","Sentinel_Tank_Files");

global.savebuff = buffer_create(1,buffer_grow,1);
ini_open_from_string("");
ini_write_real("Settings", "LastLivery", global.player_skin);

ini_write_real("Stats", "HighScore", highscore_value(1));
ini_write_real("Stats", "ScoreTotal", global.score_total);
ini_write_real("Stats", "DeathsTotal", global.death_total);
ini_write_real("Stats", "TimeTotal", global.time_played);
ini_write_real("Stats", "HighLevel", global.highest_level);

ini_write_real("Stats", "BronzeTotal", global.bronze_kills);
ini_write_real("Stats", "SilverTotal", global.silver_kills);
ini_write_real("Stats", "OrangeTotal", global.orange_kills);
ini_write_real("Stats", "RedTotal", global.red_kills);
ini_write_real("Stats", "GreenTotal", global.green_kills);
ini_write_real("Stats", "PurpleTotal", global.purple_kills);
ini_write_real("Stats", "WhiteTotal", global.white_kills);
ini_write_real("Stats", "BlackTotal", global.black_kills);
ini_write_real("Stats", "GoldTotal", global.gold_kills);
ini_write_real("Stats", "PlatinumTotal", global.platinum_kills);
ini_write_real("Stats", "TimePlayed", global.time_played);
ini_write_real("Stats", "DeathTotal", global.death_total);
var inistring = ini_close();
buffer_write(global.savebuff,buffer_string,inistring);
buffer_save_async(global.savebuff,"STStats.tank",0,buffer_get_size(global.savebuff));
global.saveid = buffer_async_group_end();
This is my Load Script:
Code:
if !instance_exists(obj_cog_save)
{
    instance_create_depth(1770, 930, -100, obj_cog_save);
}

global.loadbuff = buffer_create(1,buffer_grow,1);

buffer_async_group_begin("Sentinel_Tank_Files");
buffer_async_group_option("showdialog",0);
buffer_async_group_option("Sentinel_Tank_Files","Sentinel_Tank_Files");
buffer_load_async(global.loadbuff,"STStats.tank",0,-1);

global.loadid = buffer_async_group_end();
And this is my Save/Load Event:
Code:
var ident = async_load[? "id" ];
var status = async_load[? "status"];
var error = async_load[? "error"];

if (ident == global.saveid)
{ 
    buffer_delete(global.savebuff);
    show_debug_message("saved data status " + string(status) + " error " + string(error));
    if instance_exists(obj_cog_save)
    {
        with(obj_cog_save) instance_destroy();
    }
}
else if (ident == global.loadid)
{
    var buffstring = buffer_read(global.loadbuff,buffer_string);
    ini_open_from_string(buffstring);
    global.starting_livery = ini_read_real("Settings", "LastLivery", 0);
    
    global.score_total = ini_read_real("Stats", "ScoreTotal", 0);
    global.death_total = ini_read_real("Stats", "DeathsTotal", 0);
    global.highest_level = ini_read_real("Stats", "HighLevel", 0);
    if room = Start
    {
        global.time_played_past = ini_read_real("Stats", "TimeTotal", 0);
    }
    
    global.bronze_kills = ini_read_real("Stats", "BronzeTotal", 0);
    global.silver_kills = ini_read_real("Stats", "SilverTotal", 0);
    global.orange_kills = ini_read_real("Stats", "OrangeTotal", 0);
    global.red_kills = ini_read_real("Stats", "RedTotal", 0);
    global.green_kills = ini_read_real("Stats", "GreenTotal", 0);
    global.purple_kills = ini_read_real("Stats", "PurpleTotal", 0);
    global.white_kills = ini_read_real("Stats", "WhiteTotal", 0);
    global.black_kills = ini_read_real("Stats", "BlackTotal", 0);
    global.gold_kills = ini_read_real("Stats", "GoldTotal", 0);
    global.platinum_kills = ini_read_real("Stats", "PlatinumTotal", 0);
    global.time_played = ini_read_real("Stats", "TimePlayed", 0);
    global.death_total = ini_read_real("Stats", "DeathTotal", 0);
    ini_close();
    if instance_exists(obj_cog_save)
    {
        with(obj_cog_save) instance_destroy();
    }
    buffer_delete(global.loadbuff);
}
global.loadid = noone;
The article says that if you try to save normally the game will freeze but I have a way to prove it is saving asynchronously, notice how I create an object called 'obj_cog_save' and delete it when the save/load is complete. When in normal Windows, the Cog sometimes will show up for a frame, and other times won't show up at all meaning that it is definitely asynchronous. Other than some minor tweaks and adding in all my files to save, this is unchanged code from the Article so I'm unsure what's wrong. Obviously saving files is a massive part of basically every game so if I can't get this to work, I've basically wasted £100 for a UWP licence. Thank you for reading!
 
Hello @Ryan Scorpion

I have 3 games published on android and xbox called Ralph. I use the save system with files and during the game I make several saves and loads without any problem of locking using the runtime 2.2.3.344. When the gamemaker updated the runtime, either after that version, the save system completely stopped working when something was xbox live. It drove me crazy, until I found out it was the runtime. I don't know if yoyo removed the function or it is a bug, the question is that I had to use the runtime 2.2.3.344 again to not have more problems until I found a definitive solution. I was unable to implement the save function according to the yoyo tutorial. Try to use "with" clause, like this:

with(obj_cog_save)
{
global.loadbuff = buffer_create(1,buffer_grow,1);

buffer_async_group_begin("Sentinel_Tank_Files");
buffer_async_group_option("showdialog",0);
buffer_async_group_option("Sentinel_Tank_Files","Sentinel_Tank_Files");
buffer_load_async(global.loadbuff,"STStats.tank",0,-1);

global.loadid = buffer_async_group_end();

}

and I think you should use:

if(instance_number(obj_cog_save) <=0)
{
instance_create_depth(1770, 930, -100, obj_cog_save);
}
 
Last edited:
Hi! Thanks for the reply.

I'm honestly surprised you found this since it's quite old but the problem still persists so... Anyways yeah that would be the problem, I usually just use the most recent version (that's not a BETA), so I'm currently using 2.2.5.378 which is way above the version where it stops working.

The other question I have is why replace !instance_exists with instance_number <= 0? Surely in this context they preform the same action or is it a case where one requires more computational power than the other?

I take it the 'with' clause idea is simply to reduce my 'with(obj_cog_save) instance_destroy();' to just 'instance_destroy();' right? Or does it help with the saving/loading code, because in my mind, I can't really see a way in which it would help the saving/loading process.

Lastly, just out of interest, have you been able to properly publish your game with UWP or have you had to abandon it due to the lack of support? I mean, if you look at articles for the other export points (such as Windows or Android), there are many detailing how to do nearly everything, meanwhile UWP has 6. 3 are for setting up devices, 2 are for publishing and the last one doesn't even work. Sorry if I seem a little annoyed, it's just that UWP has been a literal curse/nightmare for me for all the time I've had it and I'm really annoyed at the lack of support for it.
 
I am also having the exact same issue. I want to pass certification as my game is nearly complete but the saving and loading functions are so strange to me. I update to the latest version and it seems to work now. But the save game section in the xbox interface shows no saves and if I build my game again the previous save is discarded. I agree with the above that UWP help documentation is not very helpful.
 
Top