• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker [SOLVED] Included .ini doesn't save but a save is made somewhere

S

SamSam

Guest
Dear GMC, could you help me with this issue, please ?

I NEEDED

An UTF-8 .ini file to save french strings

A way for the user to choose which .ini to load into the software


I DID


Create the UTF-8 .ini file

Include it into the project (named "config_test.ini")
When save button is clicked it does :

Code:
ini_open("config_test.ini");
ini_write_string("Section", "Key", "test");
ini_close();


IT HAPPENED


The build creates the .ini file into the folder

When I press the save button it saves the value (I am able to load it back)
But config_test.ini is still empty (and when I delete it, the software can still load the previously saved value)


I TRIED


ini_open("Settings/config_test.ini");

ini_open("config_test.ini");

Preparing the section and the key with a random value in the .ini file before the build

Leaving the .ini file perfectly empty before the build

Coding "test" as a value to write

Coding the value to write as a variable set in a create event

Simplifying the problem by making a new project with only this save/load feature : exact same result



VERSIONS


IDE v2.2.1.375
Execution environment v2.2.1.291


I would be very grateful for your help !
 
Last edited by a moderator:

obscene

Member
The version you are saving/loading from is probably in your appdata/local folder. It's in Global Game Settings under Windows/General called Save Location.

The clean version you imported can be found by right clicking the resource in Included Files and selecting Open in Explorer. But as soon as your game saves it, it ends up in the appdata folder.

At least I think I'm telling you right. I use INI files and external files separately so not 100% sure what happens when you mix the two.
 
S

SamSam

Guest
Thank you for helping me !

I found the file in the localappdata as you said. And it is in ANSI so this confirms that the software creates an .ini file as if I didn't include my own.


Is there a way to clarify to GMS that I want it to use my included "config_test.ini" and not one he would create ?
The more surprising is it actually creates the UTF-8 file into the .exe and data folder, but just not uses it.

 

Sam04

Member
I'm afraid this one does not have a solution. The "included files" folder is read-only. So when you try to modify them GM:S actually just creates a copy with the changes you made in the "appfolder" and uses that one everytime you try to open it instead of the one in the "included files" folder.

This is fundamentally a flaw in how GM:S handles external files since, as far as I know, there is no way to save a file with the UTF encoding... or, for that matter, any other encoding. Sorry.

As long as you only use it to read its content, it will remain with its special characters. If you absolutely must save a file with strings with special characters then the solution would be to code file reader functions that accepts special characters and use them. Although that's extra work it would be a solid solution.

Edit: Also, more information on the sandbox way GM:S handles files.
 
Last edited:

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
This is fundamentally a flaw in how GM:S handles external files since, as far as I know, there is no way to save a file with the UTF encoding... or, for that matter, any other encoding. Sorry.
Your information might be 7-8 years out of date - GM versions starting with 8.1 strictly use UTF-8 encoding, so topic author's problem is in something else. You can conduct the test yourself in no more than 2 minutes:
upload_2019-1-12_7-30-45.png
 

Sam04

Member
Your information might be 7-8 years out of date - GM versions starting with 8.1 strictly use UTF-8 encoding, so topic author's problem is in something else. You can conduct the test yourself in no more than 2 minutes:
View attachment 22770
You are correct. I checked and indeed saved it UTF. Also you were correct in my information being out of date (I started using GM with the version 6).

I tested it a few more times and it seems that if your text does not contain any special character it will automatically save it as an ANSI. Once I changed the text to add one special character and tried again it did create a file with UTF encoding. So it seems that just to make it immune to this error you could create a dummy section/key with a bunch of accentuated characters and the next time GM:S creates the game bundle copy inside the local directory it will create it with the desired UTF encoding.
TestINI1.JPG TestINI2.JPG
 
S

SamSam

Guest
Thank you so much for your help !

I tested it too and it was indeed UTF-8, so this makes a problem solved !


I still have to find out how to allow the user to easily choose which .ini to load and where, and I will try to use get_save_filename().

I will tell you if it worked.

Thank you again !

 
S

SamSam

Guest
It is working perfectly !

SAVING

Code:
ini_open(get_save_filename("ambianceur|*.ini", ""));
ini_write_string("text","text1", text);
ini_close();

LOADING
Code:
ini_open(get_open_filename("ambianceur|*.ini", ""));
text = ini_read_string("text","text1", text);
ini_close();
Thank you GMC !
 
Top