0 Favourites

How do I load a web-based JSON file with Construct 2?

  • As the question asks, I have a web file that loads board game data. However, I'm not sure how to load this data with Construct 2. I can't see any methods from glancing at the manual, but I might be missing something.

  • You can load the json file into either dictionary or array... my preference would be array. You can also save that data back into json into webstorage and then retrieve it from there.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Well say that I load the file with AJAX and have the responses. It's possible for the file to have nested responses, representing individual squares in the game board. How easy would it be to read that file?

  • If I understand...

    Very easy...

    Using ajax, load json into array.

    Nested responses?

    I create array within array

    0 square1, x, y, bla, ble, blo etc

    0 square2, x, y, bla, ble, blo etc

    0 square3, x, y, bla, ble, blo etc

    etc

    I write a function and pass info to the function getdata using params, I then have function return value (whatever it is I was fetching)

    Reading/writing to array is simple easy

  • Right, like:

    Status: 0

    Block: A

    Data {

    A,

    B,

    C,

    D,

    E },

    {

    A,

    B,

    C,

    D,

    E },

    {

    A,

    B,

    C,

    D,

    E }

    • Not the actual structure of the file, just as an example.
  • Yeah, you can do that. You can even save json files into an array/dictionary and load it from there.

    You can save data as deep as you want... and make it is complicated or simple as you want. It is all dependant on what you want to achieve.

    you could use dictionary

    Status 0

    block A (json of an array)

    block B (json of an array2) etc

    Check out the store tools and c2 data editor to give you an idea of what is possible.

  • Thanks! I really want to use Construct 2 for this little project I'm working on. I was just having a hard time finding any information on the capability of loading JSON, which is a must. However, this seems like it'll be fairly easy. I'm used to working in raw Javascript, but C2 seems like the best tool I could use for quick prototyping and perhaps full build, particularly with the audio capabilities (after messing with systems like EaselJS and others)

  • Thanks! I really want to use Construct 2 for this little project I'm working on. I was just having a hard time finding any information on the capability of loading JSON, which is a must. However, this seems like it'll be fairly easy. I'm used to working in raw Javascript, but C2 seems like the best tool I could use for quick prototyping and perhaps full build, particularly with the audio capabilities (after messing with systems like EaselJS and others)

    C2 is fantastic for prototyping, I got it for that reason, but the strange thing is it is so much quicker to build fully functional apps than raw coding - that I haven't touched code for awhile - lol.

    Special note, C2 json and normal json are slightly different...you need to

    {"c2array":true,"size":[20,4,1],"data":[[[0],[4],[1484],[125]],[[0],[3],[1484],[378]],[[0],[3],[1484],[378]],[[0],[2],[1484],[604]],[[0],[2],[1484],[604]],[[0],[2],[1484],[604]],[[0],[1],[1484],[800]],[[0],[1],[1484],[800]],[[0],[1],[1484],[800]],[[0],[1],[1484],[800]],[[1],[4],[1777],[135]],[[1],[3],[1777],[378]],[[1],[3],[1777],[378]],[[1],[2],[1777],[604]],[[1],[2],[1777],[604]],[[1],[2],[1777],[604]],[[1],[1],[1777],[800]],[[1],[1],[1777],[800]],[[1],[1],[1777],[800]],[[1],[1],[1777],[800]]]}
    [/code:3avlq7rd]
    Just build a quick array or dictionary and use on start of layout to download to json to see.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)