How do I save the data from an array to an existing JSON?

0 favourites
  • 3 posts
From the Asset Store
DATA+ (Addon Pack)
$18 USD
20% off
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • Hello

    There are 5 arrays in my game, each meant to provide data for one of 5 campaigns and after the game starts they each load that data from one of 5 JSON project files. During the game the data in the arrays changes, like number of completed levels or level scores and such and ideally I would like the game to save the data in the arrays back to their respective JSON files but I have no idea how to do it.

    I've been searching the forum for an hour and since I can't find anything I will assume there's a simple catch I'm missing (again). I've managed to save the modified data from my arrays using Local Storage and then load it back up but Local Storage creates it's own files apparently and that leaves me with 5 extra JSON files that are only used on the very first run of the game. Right now it's not a big deal but it will be once I start using arrays and JSON to save levels.

    So is there a way to simply save the data from an array back to the JSON project file it was loaded from?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Probably not. For security reasons Javascript tends to limit access to various things, otherwise the web would be full of dodgy scripts which changed all sorts of things. Javascript is very sandboxed.

    I don't quite see why you'd want to. Your 5 JSON files are your games initial state, and your localstorage version is the current state of the game. Overwriting your original files sounds like a bad idea - supposing you wanted to restart the whole game, where would you get your original data from.

    More to the point, does it *matter* ? JSON files, even quite complicated ones, take up very little space compared to sound or graphics files.

  • Probably not. For security reasons Javascript tends to limit access to various things, otherwise the web would be full of dodgy scripts which changed all sorts of things. Javascript is very sandboxed.

    I don't quite see why you'd want to. Your 5 JSON files are your games initial state, and your localstorage version is the current state of the game. Overwriting your original files sounds like a bad idea - supposing you wanted to restart the whole game, where would you get your original data from.

    More to the point, does it *matter* ? JSON files, even quite complicated ones, take up very little space compared to sound or graphics files.

    Well, at least I wasn't overlooking something. Thanks for explaining, I hadn't thought about the initial state issue so I guess I'll just continue with LocalStorage + starting JSON files.

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