• 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!

SOLVED I need assistance with Save File Directory

Ace Catel

Member
I want to be able to save my game's files in a custom location instead of placing it in the default: Local App Data

So far, I learned to create a directory using this code, though I have not tested it yet. I assume this would create a folder in the same location where the executable file is. (If I'm wrong, please inform me! That would be very appreciated)

GML:
if !directory_exists("saved_files")

{ directory_create("saved_files"); }

ini_open(working_directory + "\saved_files\" + USERNAME+".ini"); // path + filename
It was found from this website: https://steamcommunity.com/app/214850/discussions/0/45350244780983621/

I know I can use game_save("filename") to save it, but will it save in the directory? What else do I need to ensure that it saves through that directory I want to set up?
- I plan to have a button that will save the state of my game into a file. Nothing too fancy is necessary so long as it can save progress one way or another.
- I would also appreciate information on Loading the file as well.

I'm still working hard on my project, and I hope to hear from anyone willing and able to help!
 
Last edited:

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
I want to be able to save my game's files in a custom location instead of placing it in the default: Local App Data
The most important question here is: Why?
Doing this implies deactivating a security feature, and there'd better be a good reason for overriding the system that's in place both to protect your game's players, yourself from explaining to publishers that your game absolutely needs to be able to write to anywhere as well as from playing Russian roulette about whether your game will have permissions to use whatever location you pick. Otherwise, I'd say don't bother and go with the default location.

So far, I learned to create a directory using this code, though I have not tested it yet. I assume this would create a folder in the same location where the executable file is. (If I'm wrong, please inform me! That would be very appreciated)
It doesn't. That'll also default to AppData unless you provide an absolute file path. Doing the latter requires you to deactivate the sandbox and puts you at the mercy of the operating system's permissions, as you are not guaranteed to be able to write to any other location.

I know I can use game_save("filename") to save it, but will it save in the directory? What else do I need to ensure that it saves through that directory I want to set up?
- I plan to have a button that will save the state of my game into a file. Nothing too fancy is necessary so long as it can save progress one way or another.
- I would also appreciate information on Loading the file as well.
First of all, about formatting file paths:

TLDR: Remove working_directory, remove the leading backslash, convert all other backslashes to forward slashes.

The "folder in the same location where the executable file is" can not be written to without circumventing the sandbox via a file I/O extension.
 
Last edited:

Ace Catel

Member
Oh, I see now.
Thank you very much for the information

I mostly wanted to have the save files be easily accessible by the player in the event they wish to delete the game and the save data as well. I've never worked with save data before so I've been (poorly) assuming things.
 

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
In that case, the common solution is to provide your players with a button that lets them open their save file directory, copy the path to their clipboard or even just displaying the save file path.
 
cant you do it in-game? Most if not all games have a "delete file" option next to the "load" option.
99.9999% of people will mess with delete them from within the app, anyway. Appdata is a hidden folder, so it should also not be the only place to be able to delete your files, some users won't even know what that folder is.
But yeah, as Tsuka said, you'll get flag like hell with AV/Windows Defender/Unknown Publisher prompts and warnings if you don't use the sandbox.
And getting an app certified for this stuff is VERY expensive (not within most Indie budgets for sure)
 
Top