On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Hey FieryLion, thanks so much for the response! Tried both things you suggested and neither have worked for me yet. Tried naming my file something very specific, like "dive-bitsloth-129304878321094" and no success. I also tried creating a new directory called "Saves/" and using working_directory like you suggested - no luck there either. I may be coding it wrong, so will take another look, but is there anything else you know of I could try?

Thanks!

what browser are you using to test your game on Itch? I know that Brave browser won’t save your game data, also make sure you are not in Incognito mode

Oh, good point. But yeah, just using classic Chrome without incognito mode.

(1 edit)

this is my short load code that works in html5

if (!file_exists(working_directory + "profiles.json")){
    var file = file_text_open_write(working_directory+"profiles.json");
    profiles = ds_map_create();
    file_text_write_string(file, json_encode(profiles));
    file_text_close(file);
}else{
    var file = file_text_open_read(working_directory+"profiles.json");
    var content = file_text_read_string(file);
    file_text_close(file);
    profiles = json_decode(content);
}
(1 edit)

Hey FieryLion,

Hope all is well and thank you for the in-depth code. Apologies for the late response as I haven't gotten a chance to work on this till now. Your code was helpful, but I'm actually saving my game in a bit of different way. I write all the information into a data structure first, then push to array. Then using "json_stringify" I turn the array into a json string and save to a temporary buffer that includes my save file. 

Here's my code after I've determined which values I want to save:

// STEP 3 - JSON STRINGIFY data (convert from array to string)
var json_string = json_stringify(save_data);
// STEP 4 - BUFFER: create, write, save, delete
// (size is string length+1, buffer_fixed means size of buffer doesn't change, alignemnt is 1)
var temp_buffer = buffer_create(string_byte_length(json_string)+1, buffer_fixed, 1);      
buffer_write(temp_buffer, buffer_string, json_string);    // write our json_string to the buffer in string format     
buffer_save(temp_buffer, working_directory + "Saves/" + global.save_file);      
buffer_delete(temp_buffer);     
temp_buffer = -1;    // reset to -1      
show_debug_message("Game saved! " + json_string);

When loading files, it's the same process but backwards. Read from the buffer, then "json_parse", then pop values off the array and back into the objects. After working on this tonight, I feel like I've tried everything. With and without "working directory" and also using a save folder like:

if (file_exists(working_directory + "Saves/" + global.save_file)) {
...
}

Also, here's the name of my save file currently:

global.save_file = "dive-bitsloth-fIt0QNLgfAlboxByK9zdWOKRXRvzbMWeafIm4Q6LLlV9vykE5T.save";

I've tested this locally and other than some visual glitches, the saving works functionally. The screen that's coming up can only possibly appear if a save file exists, which I don't see how is possible if it's my first time running the game and have never saved before on itch's server. At this point I'm thinking there's something wrong with itch's CDN as my game saves perfectly on my local server and the 3rd set of characters is a randomly generated 50-character string. Not sure what else to do at this point.

Thanks for all the help so far,

bitsloth

So your saving and loading mechanism is working, but somehow the screen that should only show up if a save file exists still shows up on the first run?

Did you clear the save file to make sure the save file doesn’t exist? Could it be detecting a previous save file?

Yup, exactly. This is the one that's showing up:

Game Room

which should only appear if a saved file was found. I've tried doing the "Start New Game" option which finds and deletes the current save file, but it doesn't really do anything and I still see this screen. Also, the 50-char randomly generated string for the save file variable was a pretty new addition, but after uploading that and running for the first time, same problem. There shouldn't be a duplicate of it on itch's server I believe.

since your saving and loading mechanism work, I guess you can try to read that phantom file first, and if the read operation is successful then display the dialogue xD

(Use try-catch to try and read that file first)

Gotcha, so I tried loading the game (which reads from the phantom file) as soon as it enters the room, but then the game just freezes. Getting this error:

However, I think I know what's going on! I was doing some research earlier tonight and starting looking into the actual errors themselves. 403 is a permissions error, which I think means my game isn't able to access the save file on the remote server. So what I believe is happening (just an educated guess) is that somehow, the game thinks a save file exists, but when it goes to grab it from itch's remote server, it doesn't actually exist so is producing the errors above. I checked GMS2's documentation for "file_exists" and found something really interesting: https://manual.yoyogames.com/GameMaker_Language/GML_Reference/File_Handling/File...

They specifically say:

"Note that the function can only be used to check local files, but not any files stored on a remote server."

So I'm assuming that's the error, since the way I'm checking save files is using that function. However, I do know that you're also using that same function in your code and it's working, so I'm really not sure what's going on 😅.

(2 edits)

somehow, the game thinks a save file exists, but when it goes to grab it from itch’s remote server, it doesn’t actually exist so is producing the errors above.

I actually got the same error and came to the same conclusion as you in one of my games.

My solution to that was to use ini_open(filename) this function will create a new ini file if one doesn’t exist

then I check if ini_section_exists(“data”), “data” can be the section name you will write. If this section doesn’t exist then there are no save file (cus its a new ini file being created).

This is roundabout way but it should work!

NOTE: I’m not telling you to write your save data into an ini file, you just need to create an ini file as a way to check if a save file exists

Weirdly enough that was the only game I had that error with file_exists, my other games file_exists work just fine >.<