How do I manipulate this array?

  • Hello!

    Im having some troubles with an array I built from a JSON file

    The JSON file is something like this:

    {
    "c2array":true,
    "size":[2,2,1],
    "data":[
      [["Word1"],[
        ["a1"],["a2"],["b1"],["b2"],["c1"],["c2"],["c3"]]],
    
      [["Word2"],[
        ["a1"],["a2"],["b1"],["b2"],["c1"],["c2"],["c3"],["d1"],["d2"],["d3"]]]  
    ]
    }
    [/code:1w6w4gq7]
    
    So I got "Word1" with an array of values "a1","a2" etc...
    
    I turned this JSON file into an array but when I want to show the different values I dont know how to do it.
    If I use Array.at(0) I will get "Word1" value but I need the other values too. If I use Array.At(0,1) I get a 0...
    
    How can I access to the different values in this array inside an array? Thank you very much
  • How did you get the file? The JSON and the capx would help.

  • Sure, it is from a big capx, but I created a new one with only the array issue, I will show

    The json file is built from an ASP.NET/C# application and I need to use this in the C2 project

    Thanks

    [attachment=0:1rl365l9][/attachment:1rl365l9]

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's not a valid JSON file. It has array size of 2x2 but has more data.

    This will work but probably isn't what you need.

    {

    "c2array":true,

    "size":[2,2,1],

    "data":[ [["Palabra"],["a1"]],

    [

    ["Palabra2"],["a2"]]]

    }

    Edit: what is the structure you want? What are you trying to do?

  • Hello, sorry for replying late.

    I need for every word in the array, associates it to a few values, ie:

    • "Word 1" => "a1", "a2", "a3", "a4" 4 values
    • "Word 2" => "b6", "b7", "b8" 3 values
    • "Word 3" => "c4", "c5", "d4", "d5", "e4", "e5" 6 values

    ** Notice different number of values for each word

    ...

    ...

    ...

    I will have a checkerboard like this

         a   b   c   d   e   f   g   h   i   j   k   l   m
       -----------------------------------------------------
    1  |   |   |   |   |   |   |   |   |   |   |   |   |   |
       -----------------------------------------------------
    2  |   |   |   |   |   |   |   |   |   |   |   |   |   |
       -----------------------------------------------------
    3  |   |   |   |   |   |   |   |   |   |   |   |   |   |
       -----------------------------------------------------
    4  |   |   |   |   |   |   |   |   |   |   |   |   |   |
       -----------------------------------------------------
    5  |   |   |   |   |   |   |   |   |   |   |   |   |   |
       -----------------------------------------------------
    6  |   |   |   |   |   |   |   |   |   |   |   |   |   |
       -----------------------------------------------------
    7  |   |   |   |   |   |   |   |   |   |   |   |   |   |
       -----------------------------------------------------
    8  |   |   |   |   |   |   |   |   |   |   |   |   |   |
       -----------------------------------------------------
    9  |   |   |   |   |   |   |   |   |   |   |   |   |   |
       -----------------------------------------------------[/code:14egvffj]
     
    | WORD 1| | WORD 2 | | WORD 3 |    |VALIDATE|
    
    What I need to do is when I click a cell and a word, the game says me if the word is in the selected cells or not; for example if I click WORD 1 and I click "a1" cell, it will say is right; if I click WORD 1 and h5 it will say me it is wrong because WORD 1 got only "a1", "a2", "a3", "a4" values
    
    The words and their values will be defined in an external application and stored in a database or a JSON file
    
    Thank you!
  • Save it

    0 => "Word 1" , "value1", "value2", "value3", "value4", "value5", "value6" 6 values

    1 => "Word 2" , "value1", "value2", "value3", "value4", "empty", "empty" 4 values

    etc

    and write a function to fetch

    word and then its values.

  • So many ways of doing this. You could have a 1D array for the "word1", "word2" etc and a 2D array for the "a1", "a2" and "b1", "b2" etc. Then use the X index from the first array as the Y index into the second array.

    DUTOIT's way is the other I was thinking of as well. Choose whichever you think is simpler for you.

  • That's true! ok, understood! I think it can solve my problem.

    Thank you very much!

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