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

0 favourites
From the Asset Store
Casino? money? who knows? but the target is the same!
  • 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!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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?

  • 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.

  • So I did exactly as suggested in this thread (see pic).

    Yet in the debug mode I see that the AJAX.lastdata indeed contains the json content, yet the array stays completely empty.

    Any ideas?

    Thanks!

    The (tiny) project file

  • mutajon Array JSON should have a specific formatting in Construct. You can't load just any JSON string into an array. The easiest way to prepare array data in the correct format is to right-click Files folder and select New->Array

  • dop2000 Thanks!

    But say I have a large table in Google sheets/excel - what would be the easiest way to get it into an array in construct?

    (Without manually retyping it all over within construct as an array file...)

    Thanks again!

  • You can simply copy/paste values from Excel into Construct array table.

    If you have data in JSON format incompatible with C3 array, you can still use it in Construct. But you'll have to parse it into JSON object first, and then copy values into an array.

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