SOLVED Not able to write to ini file

Hi all! I'm working on making the options for this game, but I'm running into a problem with writing to the ini file to store the settings. For instance here's some code that sets the sound effects to off and attempts to store it in the ini file

sfx_ini.PNG

This does not work for some reason, but it seems like it should. I included the ini file within 'included files' here

included.PNG

And this is what the ini file looks like when its opened

sfx_ini_format.PNG

In my head I should be able to edit and read from this ini file, but for whatever reason something isn't right! Maybe its a path thing? I tried it out a few different ways to no avail. Not sure what I'm doing wrong here, but any insights into this are greatly appreciated!

Thanks for reading
 
Ok figured this out! I was navigating to the ini file by pulling it up via 'included files' in GM2 like the screenshot, but apparently that file doesn't get changed?? After manually navigating to appdata I see that the changes are indeed taking place on this other copy of the ini file. My mistake was thinking that the included file was the place to verify this (although I'm still sorta confused on what purpose this file serves if its not being changed??). Either way the in-game options are sticking around now.

Thanks!
 
Ok figured this out! I was navigating to the ini file by pulling it up via 'included files' in GM2 like the screenshot, but apparently that file doesn't get changed?? After manually navigating to appdata I see that the changes are indeed taking place on this other copy of the ini file. My mistake was thinking that the included file was the place to verify this (although I'm still sorta confused on what purpose this file serves if its not being changed??). Either way the in-game options are sticking around now.

Thanks!
I’m pretty sure that included files (or what I personally would use them for) is if I wanted to put a readme or some lore ;) into my game
 

TsukaYuriko

☄️
Forum Staff
Moderator
Allow me to elaborate on the file system to make sure you don't just draw conclusions about how it works, but understand it.

When working with the GMS 2 file system, you'll encounter two main terms. They tend to be called various things across the documentation, so I'll be calling them the first terms I encounter on the File System manual page: Game Bundle and Local Storage. In your case, you're also dealing with Included Files. Let's first establish what these are and where we find them. I'll assume the game's name is SurviveMoreThanYouDie for the example.


The Local Storage is the "save data" directory. It is readable and writable. Its location differs based on your target platform and, sometimes, your game's settings (see The File System). Using the default settings on Windows, for example, it will be %LOCALAPPDATA%/SurviveMoreThanYouDie (or C:/Users/yourname/AppData/Local/SurviveMoreThanYouDie if you prefer that way of writing it). This will be the same no matter how you run your game, as it depends solely on the game name.

The Game Bundle is the "game data" directory, or the directory the compiled game's files reside in. It is read only under all circumstances (even if you disable the sandbox). Its location is the parent directory of the game's executable file. If you run your game from within the IDE, it'll be in a subdirectory wherever you configured your IDE's temp directory to be.

The Included Files are a directory within your project. Namely, it's the datafiles directory. It is inaccessible by a running instance of the project (and while there is a way to work around this, there is no point to it). When you export your game, this directory's contents are copied to the Game Bundle.


Now that you know what all of these are, there's one more important thing to note about the file system. As you can see above, there are only two directories that are actually accessible: The Local Storage is readable and writable, and the Game Bundle is readable. Any other directory will be inaccessible to your game's process (with some exceptions, but that's beyond the scope of this post). The way your game is able to access the files you put in Included Files is solely because its contents are copied to the Game Bundle (which is readable) during compilation.

Note that all of this file system access is entirely automatic if you provide relative file paths. The engine will work out which directory to read files from and save files to.
For writing, that's easy - the only writable location is the Local Storage.
For reading, it works a bit differently. The engine will check for files in the Local Storage and the Game Bundle - in that order - and read whichever one it finds first. This means that if you have the same file in both locations, the one in the Local Storage always has precedence over the one in the Game Bundle.


So, if you "overwrite the contents of an Included File" (which is not what actually happens, hence the quotation marks), rather than overwriting the file in the Game Bundle - which is not possible because it is not writable - the new contents will be written to the only location that is writable, which is the Local Storage. If you then read a file with this file name, it will read the one in Local Storage (since a file with this file name now exists in Local Storage and that is prioritized over the Game Bundle).


To conclude:
The Local Storage is a directory that contains data that changes during the run time of a game (e.g. configurations, save files). When writing files, they are always written to this. When reading files, files in here are prioritized over ones in the Game Bundle.
The Game Bundle is a read-only directory that either contains data that doesn't ever change during the run time of a game (graphics, sounds, dialogue, item data), or contains default versions of files to be used if no such file exists in Local Storage (e.g. default configurations which the user can change in the game).
The Included Files are the datafiles directory in your project's directory. The files here are copied to the Game Bundle when you compile the game. This directory is otherwise not noteworthy and not related to the GMS 2 file system.


Let me know if anything else is still unclear.
 
Top