Just a doubt: Can I use c2 to read these informations?

Discussion and feedback on Construct 2

Post » Wed Oct 12, 2016 9:05 pm

The project needs to follow the instructions of a json file with this structure:

Image

Is it possible? is it difficult?

Please, I need some answer to figure out if I'm capable to do this project or not.

Thanks in advance.
B
74
S
14
G
4
Posts: 1,018
Reputation: 8,139

Post » Wed Oct 12, 2016 11:44 pm

You could look at the json plugin by yann and see if that's something you could work with.
Alternately you could use the browser object to access the info.

First step is to get the json data into a variable. Options include:
* using the Ajax object to get a file added to the project or even from a web address.
* pasting it into a textbox when you run the game.
* creating a variable and pasting it as the initial value.
* using the set variable action and pasting it there. For this one you'll need to first replace all the " with ' and put a pair of quotes around it.

Ok, so you get the json data with one of those methods and put it in a variable, you then run this action:
Browser: run js "window.myjson=" & variable

Then barring any js errors you should be able to access any value in the json with something like:
Browser.execjs("myjson.presentations[0].name")

It's just JavaScript so it maybe learning a bit of that could be useful.
Presentations is an array so the above accesses the first one and gets it's name. At least it should, unless I made some typo.
B
94
S
33
G
118
Posts: 5,395
Reputation: 75,851


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests