How do i use arrays?

0 favourites
  • Hod do I load a JSON (or XML/CSV) file's data into an array? I inserted an array object and gave it dimensions of 21,1000,1 - my JSON file has 21 columns and 1001 rows - with 1 row header. Do I need a For Loop to read each object pair in JSON and set it to an x,y,z in the Array? Or can I just cut and paste the entire JSON string into the JSON load field? Or do I load it as a file? Manual doesn't really help. thanks in advance

  • RealMagisterLudi

    I use this for loading json files to arrays:

    Add the AJAX object to your project.

    Create yourArray object.

    Add your.json file to your project files.

    1) System| On (trigger): AJAX| Request your.json file (tag "your")

    2) AJAX| On "your" completed: yourArray| Load from JSON string AJAXLastData

    Make sure your json file is formatted like so for a 3D array:




    "data":[ [ [,,,],











  • Thanks - I'll try that tonight

  • I have been trying to do this too, I have read every forum post I can find on the topic but can't get it to work. I have used exactly the process outlined here, but whatever I do, nothing shows up in my array. When I run debug, it shows all the values in the array as zero.

  • , there are 4 pages in this post. Which comment are you referring to? What exactly are you trying to do?

    Please also share your capx or a screenshot of your code.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Wow, thanks for such a quick reply, wasn't expecting that on a months old post! I meant the process for importing a json to an array using ajax, as described by meconbecon just above.



  • There may be errors in your .json file

    Could you share the project?

  • Yes, I thought the error might be in the json itself. Thanks. ... .capx?dl=0

  • Your link is broken, try posting it without the "https://" part

  • The link is still incorrect, can't you see?

    Make sure it's not shortened, there should not be any "..." or spaces

  • That's so annoying, it keeps truncating when I submit. I'll try this shortened version.

  • Where do I begin...

    You have a mess with quotation marks:

    ["arbor, arboris","ambulō, ambulāre","commōtus, commōtā, commōtum","diū","e, ex",quīdam, quaedam, quoddam,"nec/neque"],
    You have different number of elements in each row.
    You have specified incorrect size in JSON.
    And finally, your JSON file is saved in some weird code page 1200. Even if you format your JSON string properly, C2 can't load it from this file. Try saving your json file in Notepad with UTF-8 encoding.
    Use example from this tutorial to see how JSON should be formatted for string values:
    [url=] ... -game-card[/url]
  • Thank you so much for your help! I will have another go. I am starting from scratch here, had never even heard of a json file til a couple of days ago.

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