Problem reading from Array after loading with JSON

Get help using Construct 2

Post » Mon Sep 16, 2013 5:09 am

Hi,

I loaded my Array with a JSON string like this:
{"c2array":true,"size":[3,7,1],"data":[["Africa",1,2,3,4,5,6],["Arctics",1,2,3,4,5,6],["EasternEurope",1,2,3,4,5,6]]}

When I do Array.At(0,0) I get just "A" instead of "Africa". Likewise if I read Array.At(3, 0) I get "E" instead of "EasternEurope".

When I use the debugger to watch the Array it shows the correct Json data loaded as shown above with the correct length.

However, if I do an Array.Count it returns just 1, instead of 21.

Any help would be appreciated.
(I'm using R144)

Thanks!
B
3
Posts: 2
Reputation: 204

Post » Mon Sep 16, 2013 6:13 am

Maybe your format is wrong?

try:

{"c2array":true,"size":[3,7,1],"data":[[["Africa"],[1],[2],[3],[4],[5],[6]],[["Arctics"],[1],[2],[3],[4],[5],[6]],[["EasternEurope"],[1],[2],[3],[4],[5],[6]]]}

Note: Array.count return the number of instance for that object and not the length x,y,z of the array. You can get the x-axis with width, y-axis with height and z-axis with depth.

Reference:
https://www.scirra.com/manual/108/arrayc4sp3r892013-09-16 06:17:44
B
17
S
8
G
4
Posts: 93
Reputation: 3,190

Post » Mon Sep 16, 2013 6:16 am

Scale your text object in the editor... It does not auto scale so you either need to scale it in the editor, or at runtime with your code.

You are only displaying the first few letters because the text object probably is not wide enough.
jojoe2013-09-16 06:17:27
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Tue Sep 17, 2013 12:13 am

I don't quite understand the idea behind this but c4sp3r89, you are right. Adding the extra bracket between each parameter seems to do the trick.
B
3
Posts: 2
Reputation: 204

Post » Tue Sep 17, 2013 12:29 pm

its because of the array size you define as [3,7,1] so you need to specify 1 slot for the z-axis.

And if you do ["Africa",1,2,3,4,5,6] the enclosed [] will be 1 slot. So you cant get anything back as the format is wrong. Doing [["Africa"],[1],[2],[3],[4],[5],[6]] will set each of the item inside [] as a slot.

So basically:
[["Africa"],[1],[2],[3],[4],[5],[6]] is "size":[1,7,0]
[[["Africa"],[1],[2],[3],[4],[5],[6]]] is "size":[1,7,1]

eg1: [x0[y0][y1],[y2],[y3],[y4],[y5],[y6]]

eg2: [x0[y0][y1],[y2],[y3],[y4],[y5],[y6]],
     [x1[y0][y1],[y2],[y3],[y4],[y5],[y6]]
              

Something like that. I hope i'm not wrong. c4sp3r892013-09-17 12:30:37
B
17
S
8
G
4
Posts: 93
Reputation: 3,190


Return to How do I....?

Who is online

Users browsing this forum: evillair, gamecorpstudio, jorgmaquoi, Yahoo [Bot] and 27 guests