How do I load Ajax.lastdata to simple numbers [SOLVED]

From the Asset Store
Simplistic food icons in pixel art style. All icons are in 16 x 16 pixels.
  • Is there a really clean and easy way to split ajax.lastdata to simple numbers in a global variable so that it looks like, "0,0,1,23,4"? Currently saving ajax.lastdata into a global variable looks like this, "{"c2array":true,"size":[7,2,1],"data":[[[1286],[885]],[[1605],[693]],[[1716],[903]],[[1643],[1033]],[[1842],[1015]],[[1940],[844]],[[1989],[974]]]}"

    What I'm actually trying to do:

    I'm saving all enemy positions (XY coordinates) into a json file. Then i'm loading that json file into a global var and using tokenat to retrieve the numbers to create enemies using those X,Y positions during loading of the level. Reason why I have it as a separate file is that I have separate json files for each level to build tilemaps, enemies, items, etc... This way, I don't have to have 100+ layouts to load each level - I can just load them on the same layout after each level.

    If there is a more efficient way to do this, please let me know!

  • If you are saving an array as JSON, the cleanest way would be to use the Array object's "Load" action to load it back into an array.

  • oosyrag I usually do array load by doing, "AJAX.LastData". Since I am not loading any data through Ajax, what should I put instead of AJAX.LastData?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • oosyrag Ah, I see. It's just loading to array form ajax.lastData and then using the for each xyz element on the array to append to the global variable or text. Thanks!

  • I was assuming you were saving the JSON format to disk or webstorage/local storage, then using an AJAX Request to load the saved data. Then you can access it with LastData. Also assumed your JSON data came from an array to begin with.

    For reference for your array load question, if you have the ""{"c2array":true,"size":[7,2,1],"data":[[[1286],[885]]... ect" data (JSON format of array data) in GlobalVariable, you can use Array.Load on that GlobalVariable.

    But glad you figured it out anyway!

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