GML Saving nested maps to .ini with json_encode and its issues

Discussion in 'Programming' started by iDecided, Apr 23, 2018.

  1. iDecided

    iDecided Guest

    Hey guys, I'm running into an issue and I'm not sure if it's me or GMS2.

    I'm using GMS2 and working with saving and loading to an .ini, I'm sure many of you have done this before. I have a map with nested maps and I've added them with ds_map_add_map(). When saving, I use json_encode, write it to the .ini and when I view the file BAM! it's there.

    Here's an excerpt from the written ini file:
    affectionLevelsMap="{ "jacob": 0.000000 }"
    The problem comes from when I then try to read that JSON string back into my game. I noticed that json_encode writes the string out with double-quotes around the map keys. This confuses the ini_read_string function because it stores the result from json_encode() in a set of double-quotes. Thus, when I read in the string, it gets cut off prematurely.
    When I read it back using ini_read_string(), I get just the first '{' and a space, because it reads the first double-quote of the first key as the end of the string.
    "{ "
    I can see that it's writing it correctly, but I also see where it gets confused. So is this me, or is it GMS2?

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