How do I load data from Json string

Get help using Construct 2

Post » Fri Jan 09, 2015 4:56 pm

@Steely What's wrong with it? It's not loading from a project file?
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Fri Jan 09, 2015 5:30 pm

Hi ramones, thanks for your reply,

I got it working if I load it direct in the array with ajax (finaly) but I wanted it to do different now, because I don't know if it all loads fast enough in a android app, so I wanted to copy my data (txt) files from the level editor direct in the c2 code as dictionary keys key 1 to 30 (or more) for example.

The levels are created out of this 30 different level parts to generate random levels.
B
46
S
9
G
5
Posts: 110
Reputation: 3,782

Post » Fri Jan 09, 2015 5:33 pm

It should be possible to load from a dictionary key... Can't see why this is not working.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
19
S
5
G
2
Posts: 544
Reputation: 3,255

Post » Fri Jan 09, 2015 5:38 pm

I want that the level editor save in the right format so I can copy and pasta the txt file direct in the dictionary key without to edit the file because when I get a typo in there its mesh up the whole system.
B
46
S
9
G
5
Posts: 110
Reputation: 3,782

Post » Fri Jan 09, 2015 5:49 pm

Right, the editor expects you to enter a string so you have to put it in quotation marks and you have to escape any quotation marks inside the json string with double quotation marks.

Eg.
{"c2array":true,"size":[30,8,4],"data":[]}
will work when loaded from a file but if you want to paste into an event you have to change it to:
"{""c2array"":true,""size"":[30,8,4],""data"":[]}"
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Fri Jan 09, 2015 6:00 pm

ramones wrote:Right, the editor expects you to enter a string so you have to put it in quotation marks and you have to escape any quotation marks inside the json string with double quotation marks.

Eg.
{"c2array":true,"size":[30,8,4],"data":[]}
will work when loaded from a file but if you want to paste into an event you have to change it to:
"{""c2array"":true,""size"":[30,8,4],""data"":[]}"


Thanks again, at least I know now how it all works and hope that it can and going to be changed in a future release.
B
46
S
9
G
5
Posts: 110
Reputation: 3,782

Post » Fri Jan 09, 2015 6:07 pm

You can have your level editor export the data in the correct format like this:
download_escaped_json.capx


Still I'd just use project files unless you've tested it and it's noticeably slower.
You do not have the required permissions to view the files attached to this post.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Fri Jan 09, 2015 6:20 pm

ramones wrote:You can have your level editor export the data in the correct format like this:
download_escaped_json.capx


Still I'd just use project files unless you've tested it and it's noticeably slower.


Thanks I'm going to test it right away
B
46
S
9
G
5
Posts: 110
Reputation: 3,782

Post » Fri Jan 09, 2015 6:22 pm

Why don't you program the level editor to save as an array and when saving just save that array as JSON? Set key to arrayName.AsJSON would do that and guarantee everything is right...
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
19
S
5
G
2
Posts: 544
Reputation: 3,255

Post » Fri Jan 09, 2015 6:30 pm

Thanks @ramones it works like a charm, you made my day ;)

brunopalermo wrote:Why don't you program the level editor to save as an array and when saving just save that array as JSON? Set key to arrayName.AsJSON would do that and guarantee everything is right...
that's what I did but won't work like that.
B
46
S
9
G
5
Posts: 110
Reputation: 3,782

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, dand, tinhofiel and 27 guests