How do I save a JSON file with new info?

0 favourites
  • 5 posts
From the Asset Store
Source File, music and art pack for Android Negotiator
  • I'm not sure how Construct 3 saves and loads files exactly. Essentially I created a JSON file called "keyconfig.json" that has a few lines of data where the key name is the name of the button and the value is the KEYBOARD keycode that I want. I so far have code working to grab those values and assign them to in-game variables and I have code that changes the JSON values when you change stuff in the keyconfig prompt. But it is only temporary, if you close and reopen the game all of the JSON values are reset to their initial value. How can I make construct SAVE the data to the JSON file permanently?

    	"up": 38,
    	"down": 40,
    	"left": 37,
    	"right": 39,
    	"b": 90,
    	"a": 88,
    	"start": 27,
    	"select": 13
  • You can't rewrite the project file.

    The most common solution is to save the new JSON info in Local Storage. Then, when your game starts, check Local Storage - if it contains new keyconfig, load it from Local Storage. If not - use AJAX to request the default values from JSON file.

  • dop2000 how do I save a json file in local storage, local storage is like a dictionary I thought.

  • Kind of, but it allows to save the data permanently.

    When you need to save the new keyconfig - 
     Local Storage Set "custom_keyconfig" to JSON.ToCompactString
    On start of layout:
     Local Storage Check if item "custom_keyconfig" exists
    Local Storage if item "custom_keyconfig" exists
     JSON parse from LocalStorage.itemData
    Local Storage if item "custom_keyconfig" missing
     AJAX request project file....
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That worked thanks a ton

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