How do I retrieve values from a multi-dimensional array?

Get help using Construct 2

Post » Sun Apr 26, 2015 10:49 am

Well, I'm setting multidimensional array values from a JSON file to a C2 Array object:

Take something like this for example:

Code: Select all
{
   "c2array": true,
   "size": [3,2,1],
   "data": [
      [
         ["title"],
         ["desc"]
      ],
      [
         ["Frog"],
         ["Very green"]
      ],
      [
         ["Camel"],
         ["Very yellow"]
      ]
   ]
}


I have something like this to load it up:

Code: Select all
[On Start Layout ] -> AJAX -> Request words.json (tag "words")
[On "words" completed] -> Words (Array) -> Load from JSON string AJAX.LastData


Now I'm trying to use the data in this array in a Text object that I've programmatically spawned:

Code: Select all
[On Start Layout] -> System -> Create Text on layer 0 at (200, 200)
[On created Text]
    [Words is empty]
    [else]
        [Text] -> set text to Words.At[0,0,0]


Using the .At() function, I'm only getting a value of "0" and not the text from the multidimensional array. Anyone know why this is so? The JSON data appears in the array viewer in the debugger.
B
7
S
1
Posts: 42
Reputation: 1,058

Post » Sun Apr 26, 2015 11:03 am

It looks like you're trying to access the array before it has loaded. The "on start of layout" events that request the file and create the text object happen on the first tick. The "on 'words' completed" event happens some time later when the file has loaded. You'd want to move "set text to Words.At(0,0,0)" to the "on 'words' completed" event.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,670

Post » Sun Apr 26, 2015 11:03 am

check capx from the last post
how-do-i-do-this_p911080?#p911080
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Sun Apr 26, 2015 1:40 pm

Thanks guys, the function object was the answer. @Ramones - if I move that in there, the Text object won't initialize. So I called a function to create the Text object and initializing it upon creation works fine.
B
7
S
1
Posts: 42
Reputation: 1,058


Return to How do I....?

Who is online

Users browsing this forum: Lordshiva1948 and 12 guests