PHP, JSON, AJAX, and Array

Get help using Construct 2

Post » Mon Jul 15, 2013 7:40 pm

Hello,

I have a json from a php file:

{"c2array":true,"size":[3,1,1],"data":["test1","test2","test3"]}

My array in c2
width 3, height 1 and depth 1



result



Help?
B
3
Posts: 7
Reputation: 189

Post » Mon Jul 15, 2013 8:06 pm

You're setting the text to the loop's current X value (The cell's X position, not what it contains). You probably want to replace:

Append"-"&Array.CurX

with

Append"-"&Array.CurValue
B
64
S
19
G
8
Posts: 341
Reputation: 12,195

Post » Mon Jul 15, 2013 8:12 pm

Also, you activate the group, triggering this loop at every tick, so you'll have an infinity of data output. Call a function instead, or deactivate the group after.
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Mon Jul 15, 2013 8:14 pm

[QUOTE=Guizmus] Also, you activate the group, triggering this loop at every tick, so you'll have an infinity of data output. Call a function instead, or deactivate the group after.[/QUOTE]

how? do u have a example?nightwolf2013-07-15 20:17:22
B
3
Posts: 7
Reputation: 189

Post » Mon Jul 15, 2013 8:15 pm

[QUOTE=zatyka] You're setting the text to the loop's current X value (The cell's X position, not what it contains). You probably want to replace:

Append"-"&Array.CurX

with

Append"-"&Array.CurValue[/QUOTE]


same result
B
3
Posts: 7
Reputation: 189

Post » Mon Jul 15, 2013 8:28 pm

[QUOTE=Guizmus] Also, you activate the group, triggering this loop at every tick, so you'll have an infinity of data output. Call a function instead, or deactivate the group after.[/QUOTE]




result with CurX



with CurValue i got

-t -t -t

i need "test1" "test2" and "test3"nightwolf2013-07-15 20:32:01
B
3
Posts: 7
Reputation: 189

Post » Mon Jul 15, 2013 8:38 pm

I can't produce a capx right now (computer down), but if I remember well, the JSON for an array in C2 is 3 dimensional in the datas, as the array is. So you would have to load it with :
{"c2array":true,"size":[3,1,1],"data":[[["test1"]],[["test2"]],[["test3"]]]}
and not :
{"c2array":true,"size":[3,1,1],"data":["test1","test2","test3"]}
witch is consistant with your current result (taking the [0][0] of a string is the first letter)
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Mon Jul 15, 2013 9:12 pm

Works


Thank You!

Now i will try with

test1 => value1
test2 => value2
test3 => value3


i have to change my Array in c2 Height = 2?nightwolf2013-07-15 21:16:26
B
3
Posts: 7
Reputation: 189


Return to How do I....?

Who is online

Users browsing this forum: corpvs2, dop2000, farsen and 30 guests