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

Discussion in 'Programming' started by SamSam, Jan 11, 2019.

Tags:
  1. SamSam

    SamSam Member

    Joined:
    Oct 11, 2018
    Posts:
    49
    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: Jan 12, 2019
  2. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,276
    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.
     
    SamSam likes this.
  3. SamSam

    SamSam Member

    Joined:
    Oct 11, 2018
    Posts:
    49
    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.

     
  4. Sam04

    Sam04 Member

    Joined:
    Nov 26, 2018
    Posts:
    24
    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: Jan 12, 2019
    SamSam likes this.
  5. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,076
    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
     
    SamSam and Sam04 like this.
  6. Sam04

    Sam04 Member

    Joined:
    Nov 26, 2018
    Posts:
    24
    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
     
    SamSam likes this.
  7. SamSam

    SamSam Member

    Joined:
    Oct 11, 2018
    Posts:
    49
    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 !

     
  8. SamSam

    SamSam Member

    Joined:
    Oct 11, 2018
    Posts:
    49
    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 !
     
    obscene likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice