SOLVED: Deleting a file saved from the buffer

Roleybob

Member
I am implementing a JSON save system using ds_maps and ds_lists and saving the game data by writing it to a buffer and from there saving it to a file.

Saving and loading is working fine and I was about to add the option to delete the file in case the player wants to restart the game, using

GML:
if (file_exists(filename))
    file_delete(filename);
When I realised that I don't know what would happen if there were a file saved on my computer with the same file name as my save file. I've looked at the manual and it says that file_delete() "will only delete those files that GameMaker Studio 2 is able to create and parse: ini files, text files and binary files, or those files made to store game created resources like sprites or surfaces. However, it will not delete any other file."

So I have 2 questions:

Do I need to give the save file a very obscure name so that there is no chance that my game will delete the wrong file?

Is it even possible to delete a file saved in this way?

Thanks
 
1. No, unless you are creating two files with the same name yourself in GMS, you don't have to worry about conflicts with other files. GMS will (generally) target the "working_directory" as they call it, which is basically just a folder that your game creates (in windows, usually at C:\Users\Username\AppData\Local\Game Name), unless you are specifically targeting other folders and have sandboxing disabled.

2. Yes, you can delete any file you've saved previously by simply using the filename you gave the file when you saved it as the argument in the file_delete function.
 
Last edited:
Top