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

Get help using Construct 2

Post » Tue Feb 16, 2016 11:45 pm

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!
Last edited by jook00 on Wed Feb 17, 2016 5:11 am, edited 1 time in total.
B
58
S
19
G
3
Posts: 445
Reputation: 6,300

Post » Wed Feb 17, 2016 12:09 am

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.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Wed Feb 17, 2016 3:16 am

@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?
B
58
S
19
G
3
Posts: 445
Reputation: 6,300

Post » Wed Feb 17, 2016 5:11 am

@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!
B
58
S
19
G
3
Posts: 445
Reputation: 6,300

Post » Wed Feb 17, 2016 6:46 am

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!
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438


Return to How do I....?

Who is online

Users browsing this forum: Lancifer and 10 guests