How do I load a web-based JSON file with Construct 2?

Get help using Construct 2

Post » Mon Oct 06, 2014 7:45 pm

As the question asks, I have a web file that loads board game data. However, I'm not sure how to load this data with Construct 2. I can't see any methods from glancing at the manual, but I might be missing something.
B
5
Posts: 7
Reputation: 237

Post » Mon Oct 06, 2014 7:52 pm

You can load the json file into either dictionary or array... my preference would be array. You can also save that data back into json into webstorage and then retrieve it from there.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Mon Oct 06, 2014 8:07 pm

Well say that I load the file with AJAX and have the responses. It's possible for the file to have nested responses, representing individual squares in the game board. How easy would it be to read that file?
B
5
Posts: 7
Reputation: 237

Post » Mon Oct 06, 2014 8:24 pm

If I understand...

Very easy...
Using ajax, load json into array.
Nested responses?
I create array within array

0 square1, x, y, bla, ble, blo etc
0 square2, x, y, bla, ble, blo etc
0 square3, x, y, bla, ble, blo etc
etc

I write a function and pass info to the function getdata using params, I then have function return value (whatever it is I was fetching)

Reading/writing to array is simple easy
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Mon Oct 06, 2014 8:27 pm

Right, like:

Status: 0
Block: A
Data {
A,
B,
C,
D,
E },
{
A,
B,
C,
D,
E },
{
A,
B,
C,
D,
E }

- Not the actual structure of the file, just as an example.
B
5
Posts: 7
Reputation: 237

Post » Mon Oct 06, 2014 8:39 pm

Yeah, you can do that. You can even save json files into an array/dictionary and load it from there.
You can save data as deep as you want... and make it is complicated or simple as you want. It is all dependant on what you want to achieve.
you could use dictionary
Status 0
block A (json of an array)
block B (json of an array2) etc

Check out the store tools and c2 data editor to give you an idea of what is possible.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Mon Oct 06, 2014 9:20 pm

Thanks! I really want to use Construct 2 for this little project I'm working on. I was just having a hard time finding any information on the capability of loading JSON, which is a must. However, this seems like it'll be fairly easy. I'm used to working in raw Javascript, but C2 seems like the best tool I could use for quick prototyping and perhaps full build, particularly with the audio capabilities (after messing with systems like EaselJS and others)
B
5
Posts: 7
Reputation: 237

Post » Tue Oct 07, 2014 6:44 am

Teonnyn wrote:Thanks! I really want to use Construct 2 for this little project I'm working on. I was just having a hard time finding any information on the capability of loading JSON, which is a must. However, this seems like it'll be fairly easy. I'm used to working in raw Javascript, but C2 seems like the best tool I could use for quick prototyping and perhaps full build, particularly with the audio capabilities (after messing with systems like EaselJS and others)


C2 is fantastic for prototyping, I got it for that reason, but the strange thing is it is so much quicker to build fully functional apps than raw coding - that I haven't touched code for awhile - lol.

Special note, C2 json and normal json are slightly different...you need to
Code: Select all
{"c2array":true,"size":[20,4,1],"data":[[[0],[4],[1484],[125]],[[0],[3],[1484],[378]],[[0],[3],[1484],[378]],[[0],[2],[1484],[604]],[[0],[2],[1484],[604]],[[0],[2],[1484],[604]],[[0],[1],[1484],[800]],[[0],[1],[1484],[800]],[[0],[1],[1484],[800]],[[0],[1],[1484],[800]],[[1],[4],[1777],[135]],[[1],[3],[1777],[378]],[[1],[3],[1777],[378]],[[1],[2],[1777],[604]],[[1],[2],[1777],[604]],[[1],[2],[1777],[604]],[[1],[1],[1777],[800]],[[1],[1],[1777],[800]],[[1],[1],[1777],[800]],[[1],[1],[1777],[800]]]}

Just build a quick array or dictionary and use on start of layout to download to json to see.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718


Return to How do I....?

Who is online

Users browsing this forum: 25games, Artcadev, brunopalermo, MaxxMunnn, mcscooter, Soluna Software and 24 guests