Ryan Scorpion
Member
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:
This is my Load Script:
And this is my Save/Load Event:
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!
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:
UWP: Asynchronous Saving And Loading When Targeting Xbox One Devices
A number of long-time GML function for saving files work in a synchronous manner, which means they make the game wait while the load or save operation is performed. Therefore, if you use these func...
help.yoyogames.com
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();
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();
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;