How do I populate a array with json data?

0 favourites
  • 6 posts
From the Asset Store
Easy to use shop and inventroy populated by an array!
  • Hello people,

    I've seen a lot of posts about it. But I don't know where my error is, please help:

    In debug:

    I've already tried Load from JSON String "AJAX.LasData", but nothing happened.

    Thank you who can help. :)

  • the action that loads an array from json expects a very specific format. if you just wanted to store a json string in the array, you have to set one of the index of the array to json "string".

  • construct arrays are actually 3 dimensional, so the array represented as json looks like this

    { "c2array": true, "size": [ 1, 1, 1 ], "data": [ [ [ "stuff" ] ] ] }

    you would need to do something like this

    + System: On start of layout

    -> Array: Set value at 0 to "{""enemies"":[2,2], ""position"":[1,2], ""wait"":[0,0]}"

    notice you have to escape the double quotes

  • Here's an example C2 project - it should work fine in C3:

    dropbox.com/s/z6gbnqa22z7x5uy/ajaxArray.capx

    You can check out the json structure under the file folder in the project bar. As piranha305 mentions, you need a specific json format in order to load it into an array.

    EDIT: Sorry piranha305 - posted my reply without checking for any updates :-)

    In C3, instead of using the On "wave" completed condition, you can add a "wait for previous actions" action under the AJAX request action and then Load ar_HelliWave from AJAX.LastData straight after that.

  • It's all good man, the more info the better.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey guys thx a lot!

    Finally I understood that it needs to have a specific format ... It was enough to do that and it worked.

    You are awesome!

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