Is there a way to write to the JSON file?

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Is there a way to write to one of the projects JSON files? I wanted to use it as kind of a database.

    If there is no way to do this, how much would be the performance impact and memory usage of an javascript object containing thousands of key/value pairs? (Up to 30.000 - 50.000)

    And would it be possible to save this object to one of the projects global variables and save&load from local storage?

    Thanks in advance!

  • Funny, someone asked almost exactly the same questions 4 days ago.

    You can't write to JSON files. Well, it may be possible with some php script running on the server, but this will change the database for all users.

    Don't think that saving/loading 30-50K records in local storage will be a problem if you are not doing this too often. And of course, it depends on the data. You can estimate the size of your array/dictionary: len(Array.AsJSON)

    If it's less than a couple of megabytes, I guess you should be fine.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • dop2000 thank you for your answer. :)

    Ok that is a bit unfortunate.

    Then I will set the data up as a javascript object via script event and then load it to a global variable. For saving and to use that object with the eventing system.

    What I wonder is however, how can I make this object readable by the runtime engine? Do I have to parse it or something like that?

    It is inpractical, that there is no eventing system for dealing with js objects, like with the arrays.

    I need the data structure to be a js object. Arrays would be a pain.

  • A quick google search told me that you can use .stringify(anObject) and JSON.parse(string) to convert objects to strings and back. So convert to a string, set this string to a global variable, save this variable in Local Storage.

  • Thank you! This will help me later.

    Now I am a little despairing about how I can create nested objects with the eventing system.

    I am trying to do something like this:

    Characters: [
    
    	{
    	id: loopindex
    	class: randomClass()
    	hp: getHP(self.class)
    	},
    	
    	{
    	id: loopindex
    	class: randomClass()
    	hp: getHP(self.class)
    	},
    
    	{
    	id: loopindex
    	class: randomClass()
    	hp: getHP(self.class)
    	}
    
    ]
    

    So inside the object Characters each of the characters should have his own object with own key: value pairs for storing its id, class, hp and many more.

    I guess I have to push an array and inside that array an empty object or so. But I can't get it to work.

    The current state of my events:

    I changed it many times but it is hard without an example. :(

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