SOLVED Create a Directory/Folder

Hello! Well I want to store some game data in a series of short .ini files. The thing is I want that if you choose to create the data for the first time It creates a series of folders where the files will be stored.

Seems easy but I was reading the documentation page for directory_create(dname) and everything was ok until I did read " This function will creates a directory with the given name in the sandboxed local save area ". Well the thing is I want to create a folder in the folder where the game is stored, but i'm not sure if that sentence says that it will create it in like some "Virtual Space" not really accessible. Im going to try to explain myself better; I'm not sure if it will create a real folder inside your game folder or it will do some kind of trick inside the game and won't be accessible from the Windows File Explorer Later.

Somebody has any experience with this? Thanks in advance!
 

TsukaYuriko

☄️
Forum Staff
Moderator
The "sandboxed local save area" depends on the platform. Sandboxed means that you can't write to a specific folder you want, but to a predefined folder (unless you disable the sandbox, then you can write to any folder that is not the folder the game's .exe file resides in and the game process has permission to write to).

You can learn more about the file system in the manual.
 

kburkhart84

Firehammer Games
Don't worry, that data and folder is accessible later, though it's not typically in the same folder as the executable, rather it is in the appdata or user data area(which is "best practice" with Windows apps). And of course, that data is easily accessible later next time you open the game, as well as directly with Windows explorer(which generally isn't needed). Then on other platforms, the folder is in different places depending on where the app has permission to write to and the "best practice" for said platform. But in those cases as well, the files are accessible on later runs of the game. I can't promise they will be found via file explorers on something like iOS or Android, but the game itself will have no trouble accessing them.
 
The "sandboxed local save area" depends on the platform. Sandboxed means that you can't write to a specific folder you want, but to a predefined folder (unless you disable the sandbox, then you can write to any folder that is not the folder the game's .exe file resides in and the game process has permission to write to).

You can learn more about the file system in the manual.
In that case for what i'm actually reading there if I would just write/read and do stuff for example in Desktop/MyGameFolder/ I wouldn't need to disable the sandbox because if I just want to do stuff inside the game local folder its everything ok. But if I would like to write something far away from the game folder (Eg: Images, or System32, or wherever) I would need to disable the sandbox mode right?

Thanks for such a fast answer!
 
Don't worry, that data and folder is accessible later, though it's not typically in the same folder as the executable, rather it is in the appdata or user data area(which is "best practice" with Windows apps). And of course, that data is easily accessible later next time you open the game, as well as directly with Windows explorer(which generally isn't needed). Then on other platforms, the folder is in different places depending on where the app has permission to write to and the "best practice" for said platform. But in those cases as well, the files are accessible on later runs of the game. I can't promise they will be found via file explorers on something like iOS or Android, but the game itself will have no trouble accessing them.
Well if im honest it would be perfect if I were able to do it just in the game folder instead in %Appdata% because it would be easier for others to easily delete and check that files for later use.

Also this has some "sharing" purposes because I was thinking about generate myself that data I need and then send to my friends who test it with that data already generated. That would be easy if all the data is in the same folder of the game and I can quickly do a .zip / .rar with the whole game folder instead of having to go to %appdata% and copy/paste stuff there...
 
Last edited:

kburkhart84

Firehammer Games
Manual page

You should really check the manual as suggested above. There is a run-time variable that gives you the directory for the executable itself. But the engine won't let you write there, even if you disable the sandbox. You would have to use a separate extension to do it.

That said, Windows specifically has gone away from having that type of data in the program directory. Gamemaker followed suit of course. I think users are now more used to the idea as well. So you shouldn't have any issues with them messing around with the files outside of the game if that is part of what you are needing to happen. It isn't a new concept anymore. I know old school was different, but things change and we have to move with the times.
 

TsukaYuriko

☄️
Forum Staff
Moderator
In that case for what i'm actually reading there if I would just write/read and do stuff for example in Desktop/MyGameFolder/ I wouldn't need to disable the sandbox because if I just want to do stuff inside the game local folder its everything ok. But if I would like to write something far away from the game folder (Eg: Images, or System32, or wherever) I would need to disable the sandbox mode right?

Thanks for such a fast answer!
You have to disable the sandbox if you want to write to any location other than the one defined in the manual, but this usually shouldn't be needed.
You may not be able to write to write to any such folder you explicitly define due to operating system level permissions, so you are advised not to touch the path finding, use relative paths and let your game write to the sandboxed area, as this is as close to guaranteed to be writable as it gets.

Well if im honest it would be perfect if I were able to do it just in the game folder instead in %Appdata% because it would be easier for others to easily delete and check that files for later use.
The game folder is the one folder you absolutely can not write to without using extensions. Provide your players with a "show save location" button that tells them where the files are if they need to be able to find them. The days of programs (especially games) storing settings and saves in their program folders are, for the most part, long gone.
 
Last edited:

EvanSki

Raccoon Jam Host
You can make folders by changing where the save file is going

file_exists(working_directory + "\\ScreenShots\\Screen_"+string(num)+".png")
This line checks for a png file named Screen_num.png

it will start in the working_directory (Typically "C:/user/appdata/local/YOURGAMENAME/" )
then look for a folder named ScreenShots
Then hopefully it will find the file there

using this info you could also write an jason,ini,txt file to said location by making sure the filepath has the folder you want made,
When saving a file if the folder doesnt exist Game maker will make it

IF you are reading a file and the folder does not exist it will return an error
 
Thank you all! Well I think i'm maybe a bit (And let me do the joke, no offensive goal with it) "Boomer" in this kinda stuff. I tried to do a folder and yes, is it in AppData/Local/GameName/TheFolder. Well I will just need to get used to it, I guess this avoids some glitch to delete any file you got in your hard drive or do messy stuff in your computer, so I won't disable the SandBox mode. Thank you all for the good explainations you gave me!
 
Top