Load .json file from the Files folder into Array Construct 3

  • Hi guys,

    I'm new to the forums and I apologize if this is the wrong place to post this question. I have also looked through the forums and Scirra manuals for info on this particular thing but haven't found anything or anyone that shows a specific example that can help.

    I'm on the paid plan for Construct 3 and so I have access to the Array Editor (which is awesome by the way!). What I did was right click on the Files folder in the Project navigation pane, and selected New -> Array. I then made my Array:

    Height: 2

    Width: 2

    Depth: 1

    So I saved the array as array.json (just for this example), and it appears in the Files folder.

    Now I create my Array object in my layout (double click in layout and add array object)

    So I want to load the contents of array.json in my Files folder into the new Array object. I tried to use the Load from JSON String, but there doesn't seem to be a way to specify that array.json file that I want to load. I'm guessing there is an easy way to do this without having to load the actual JSON String and just load the file since it is in the Files folder in my Project?

    Really would appreciate any help from folks who have done this before, and apologies again if this is the wrong place to ask or if someone has asked before, just couldn't find any info on this.

  • Hi KitaWolf,

    This is the method I use:

    Add the AJAX object to your project.

    Add the following two events:

    1. On start of layout| AJAX: Request array.json (tag "yourArray")

    2. AJAX|On "yourArray" completed |Array Object: Load from JSON string AJAX.LastData

    You can leave the size of the array object at 0,0,0 - it will automatically resize to fit the array.json data.

    If you run the game in debug mode you can check that the json data is correctly being grabbed by the AJAX request and loaded into the Array object.

  • Hey mekonbekon,

    Excellent thank you that works great! Really appreciate your help and quick reply.

  • You're welcome!

  • Can I put into the file a lot of different arrays in json format? And after loading them as needed?

  • and how can i save the array info in the json file?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • felipenune Use Array.AsJSON expression.

  • Hi, I have to load 2 arrays into my game.

    The easiest way I found is to create the arrays in the File Folder of the project manager,

    then to load it into an array objet this way :

    Add the AJAX object to your project.

    Add the following two events:

    1. On start of layout| AJAX: Request array.json (tag "yourArray")

    2. AJAX|On "yourArray" completed |Array Object: Load from JSON string AJAX.LastData

    But when I check the array with the debug mode, it seems all the data from the entire row are affected to the first line of the array, BUT the array seems to be resized at the right size !

    I don't get it... I'm in the middle of the ludum dare game jam, i didn't use construct 3 for months, i'm getting tired and this driving me crazy.

  • It's hard to say what's happening without seeing your event sheet or debug output - are you using two separate array objects, one for each array file?

    In C3 you can load multiple arrays from files in sequence as follows:

    On start (or function, or whatever):

    AJAX: Request array1.json tag "array1"

    System: Wait for previous actions to complete

    Array1: Load from JSON string AJAX.LastData

    AJAX: Request array2.json tag "array2"

    System: Wait for previous actions to complete

    Array2: Load from JSON string AJAX.LastData

  • Thank you, it appeared this was totally normal, someone on the discord told me it was just the way the debuger displayed array. Nothing is wrong, i'm just dense.

  • It's hard to say what's happening without seeing your event sheet or debug output - are you using two separate array objects, one for each array file?

    In C3 you can load multiple arrays from files in sequence as follows:

    On start (or function, or whatever):

    >AJAX: Request array1.json tag "array1"

    >System: Wait for previous actions to complete

    >Array1: Load from JSON string AJAX.LastData

    >AJAX: Request array2.json tag "array2"

    >System: Wait for previous actions to complete

    >Array2: Load from JSON string AJAX.LastData

    Thanks for this, it just resolved an issue for me while trying to load multiple json data files into separate arrays.

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