How do I manipulate this array?

Get help using Construct 2

Post » Tue Oct 21, 2014 9:57 am

Hello!

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

The JSON file is something like this:

Code: Select all
{
"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"]]] 
]
}


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
B
3
Posts: 4
Reputation: 183

Post » Tue Oct 21, 2014 10:20 am

How did you get the file? The JSON and the capx would help.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Oct 21, 2014 10:28 am

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

proyecto.capx
You do not have the required permissions to view the files attached to this post.
B
3
Posts: 4
Reputation: 183

Post » Tue Oct 21, 2014 11:08 am

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?
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Oct 22, 2014 7:38 am

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

Code: Select all
     a   b   c   d   e   f   g   h   i   j   k   l   m
   -----------------------------------------------------
1  |   |   |   |   |   |   |   |   |   |   |   |   |   |
   -----------------------------------------------------
2  |   |   |   |   |   |   |   |   |   |   |   |   |   |
   -----------------------------------------------------
3  |   |   |   |   |   |   |   |   |   |   |   |   |   |
   -----------------------------------------------------
4  |   |   |   |   |   |   |   |   |   |   |   |   |   |
   -----------------------------------------------------
5  |   |   |   |   |   |   |   |   |   |   |   |   |   |
   -----------------------------------------------------
6  |   |   |   |   |   |   |   |   |   |   |   |   |   |
   -----------------------------------------------------
7  |   |   |   |   |   |   |   |   |   |   |   |   |   |
   -----------------------------------------------------
8  |   |   |   |   |   |   |   |   |   |   |   |   |   |
   -----------------------------------------------------
9  |   |   |   |   |   |   |   |   |   |   |   |   |   |
   -----------------------------------------------------


| 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!
B
3
Posts: 4
Reputation: 183

Post » Wed Oct 22, 2014 7:51 am

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.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Wed Oct 22, 2014 7:54 am

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.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Oct 22, 2014 8:02 am

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

Thank you very much!
B
3
Posts: 4
Reputation: 183


Return to How do I....?

Who is online

Users browsing this forum: 25games, Artcadev, grodrigues and 21 guests