How do I save and load a .json dictionary file from user's folder?

0 favourites
  • 9 posts
From the Asset Store
Source File, music and art pack for Android Negotiator
  • I am using trying to use .json files to save and load the settings for my game but it simply doesnt seem to work. I am saving it to the user folder. Here is my code for saving the settings:

    And here is the code for loading it:

    Tagged:

  • When stuck, check the manual:

    construct.net/en/make-games/manuals/construct-3/plugin-reference/nw-js

    You can't read files like that. Use NWJS.ReadFile expression:

    Dictionary load from JSON string NWJS.ReadFile(path_to_the_file)

    But first you probably need to check if the file exists using NWJS Path Exists condition.

    And definitely don't do this on every tick!

  • When stuck, check the manual:

    https://www.construct.net/en/make-games/manuals/construct-3/plugin-reference/nw-js

    You can't read files like that. Use NWJS.ReadFile expression:

    Dictionary load from JSON string NWJS.ReadFile(path_to_the_file)

    But first you probably need to check if the file exists using NWJS Path Exists condition.

    And definitely don't do this on every tick!

    Thanks for the response. Using your feedback I've changed the code to this:

    (Main Menu)

    (Options)

    (Game)

    However, it still isnt working as I hoped. Looking at Debug Layout shows that the dictionary adds/changes the keys sucessfully, but the json file itself looks like this and isnt working to save/load the options:

    Also, I am uploading to Steam if that changes anything. The dictionary doesnt even seem to work at all in steam, and the json file still doesnt update.

  • Did you check if the file is being created?

    I hope the events on your first screenshot (Main Menu) are sub-events under some trigger. Because otherwise they will be running on every tick, constantly reading and overwriting the file, which may explain why it's empty.

    Can you make a bigger screenshot showing all these events at once? It's impossible to tell what can be wrong by those fragments.

  • Did you check if the file is being created?

    I hope the events on your first screenshot (Main Menu) are sub-events under some trigger. Because otherwise they will be running on every tick, constantly reading and overwriting the file, which may explain why it's empty.

    Can you make a bigger screenshot showing all these events at once? It's impossible to tell what can be wrong by those fragments.

    Do you mean the full event sheets? I'm a bit confused with what you are asking.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yes, or at least a screenshot showing their parent events and event numbers.

  • Yes, or at least a screenshot showing their parent events and event numbers.

    That may be the issue because that is all of the code that directly uses the options-saving system in the whole project (none of the events I've shown have any other condition or action, and using debug layout I know that the options works for setting the dictionary to what it should be, and that the game uses the dictionary to apply the settings properly, so it is 100% an issue with the .json save load system).

    Am I missing something in the system?

  • Update: After manually editing the contents of the file it seems to load correctly, so I think it is an issue with saving it.

  • Another update: It works now! I have no idea what I changed to make it work, but it works!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)