How do I 'Load from JSON String' into my array?

0 favourites
  • 7 posts
From the Asset Store
This collection of music is the beautiful performance of rather small strings ensemble (8 first violins, 6 second violin
  • What am I doing wrong? I just can't seem to make this work. The 'set size' to (9, 36) action is working successfully, but in the debug i'm just seeing a zeroed out array of that size.

  • haven't worked with loading arrays from json but...

    since you're using AJAX to get the json I believe the json will be in the ajax.lastdata.

    Try this.

    Working_Word_List_Array | Load from JSON string Ajax.LastData.

    And you're likely to run into another problem. You're firing off a second ajax request the instant the first comes in. Have the on ajax completed fill the array with the Ajax.LastData and then, just below that, send off the next ajax request.

    I think what you are assuming is that when the ajax request comes in that it stores that data in the 'tag'. It does not.

  • And... is there a reason you're using the ajax request? Normally that's to contact an external website to get data but I don't see any url info in your request. Is that json file stored in the project? If so, you should be able to just Json.download | "Working_Word_List_Array.json"

    I could be wrong about that. Haven't worked with loading json directly from files either.

  • The idea you mentioned in the first post is the reason why i'm running into problems. I know that I can 'Load JSON from AJAX.LastData' but I dont want to do this, because then I would need one array for each JSON that I am load (because if I didnt load it right after, the second JSON in the string of commands would replace the first as the new 'last data').

    And... is there a reason you're using the ajax request? Normally that's to contact an external website to get data but I don't see any url info in your request. Is that json file stored in the project? If so, you should be able to just Json.download | "Working_Word_List_Array.json"

    I could be wrong about that. Haven't worked with loading json directly from files either.

    Cool! I will give that a try. I was using AJAX because that's the only way i've seen to load JSONs from my project files in the past, but what you said seems way easier.

    I will do this and then report back. Thanks! :)

  • I will do this and then report back. Thanks! :)

    Alas, I added the JSON object to my project and tried to 'JSON.Download', but it made my browser download the file to my desktop... lol. Cool but not what I was going for.

    Also, I went onto the online guide and it says the following:

    It seems a little strange to me that my only option is the load it as 'LastData'. There must be a way to call it up using the 'Tag' that I set when it was loaded in the AJAX.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It seems a little strange to me that my only option is the load it as 'LastData'. There must be a way to call it up using the 'Tag' that I set when it was loaded in the AJAX.

    Update: I got it to work. I had to use the 'LastData' action, but it works.

  • Good to hear. I did some quick checking and as strange as it sounds, you do have to use AJAX to load the .json file. I would have thought that the json element could load and parse a file itself. Guess not.

    The tag is just a way to identify it when events happen. One of the things I do is create an Ajax on any event and then, under that, compare the tags to choose what to do.

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