How can I add JSON data to Y axis when I already have the X elements

0 favourites
  • 12 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • Hello I have an array with 118 elements in X. (x0 to x117)

    For each of those elements I have to get 3 indices and append them to each Y.

    EX: for X0Y0, append in X0Y1 1st index,

    in X0Y2 2nd index

    and in X0Y3 the 3rd index ...

    Exported from a JSON that loads different data for each X

    I can't get it.

  • Sorry, it's a bit difficult to understand. If you set array height to 4, you will have 3 additional elements for each X index.

    Or are you asking about an array inside of JSON object?

  • it is an array in the program in which I have to load different data from differents JSON.


    I have an array of 5x4 elements

    On the x-axis are the names. (X0, X1, X2 and X3)

    And to each X I have to add in

    3 Y, (Y1, Y2, Y3)

    Where each Y comes from a JSON but each X is a different JSON.

    How would it be done?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Where do you get these five JSON strings from? Are they stored in files, or in another array or do you request them from a server?

  • I request the JSONs by ajax from a server for each X

  • That part I get to do well and it returns the values ​​of the indices of each X that I manage to print on the screen, but I cannot get them to enter the array properly.

  • When then I don't understand what you are struggling with. Where do you store these JSON strings after you get them from the server? What is the JSON structure?

    In pseudocode, you need do something like this:

    Array For Each X element
     JSON Parse (string for this X)
     Array set at X=Self.CurX, Y=1 value:JSON.Get("key_for_Y1")
     Array set at X=Self.CurX, Y=2 value:JSON.Get("key_for_Y2")
     Array set at X=Self.CurX, Y=3 value:JSON.Get("key_for_Y3")
  • Ok, it's not that simple ...

    Because the JSON doesn't bring the 3 data that way.

    Sorry for not giving the data all together, I thought it was going to be confusing to understand, and I thought that what I wanted to do was simpler.

    Each JSON (for each X) brings 3 arrays, of which each one brings 4 objects, and I have to take object "4" from each array as an index.

    In the JSON they are the same object in different arrays. I do not know if it is well understood.

    Something like that...

    X0 -> JSON [ ["111","112","113","114"] ["121","122","123","124"] ["131","132","133","134"]]

    X1 -> JSON [ ["211","212","213","214"] ["221","222","223","224"] ["231","232","233","234"]]



    X5 -> JSON [ ["511","512","513","514"] ["521","522","523","524"] ["531","532","533","534"]]

    So in each X loop I have to enter in different Y, 3 different values ​​X0 (Y1, Y2, y3) ... X5 (Y1, Y2, Y3) where each Y are the values ​​that end in 4...

    In the JSON they are the same object in different arrays. I do not know if it is well understood.

    If you can solve this I will be eternally grateful

  • If your JSON format is this:

    {"array": [["111","112","113","114"], ["121","122","123","124"], ["131","132","133","134"]]}

    you can access each value that you need using these expressions:

    JSON.get("array.0.3") - will return 114

    JSON.get("array.1.3") - will return 124

    JSON.get("array.2.3") - will return 134

  • Ah ok, with the word "array"? because this JSON do not have names o keys, only the example.

  • It works without "array" key, then the path will be just "0.3"

    But make sure there are commas between sub-arrays in JSON:


    ["111","112","113","114"] , <- comma

    ["121","122","123","124"] , <- comma


  • OK great, now that work well... Thanks so much for your time!!

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