troubles loading json data

Get help using Construct 2

Post » Sun Jul 14, 2013 3:16 pm

my goal is to save the positions and types (which sprite is it) of my sprites into json data, so that i can load unique levels to my game. i'm also using a dictionary to manage the data. i have a key for the xposition, yposition, and type. when the game starts up it should take the json data from the file and create the objects in their appropriate positions.

my problem is loading the json data from the file. i imported the json file to my files folder in the project.

https://www.dropbox.com/s/0v6fzf6co8x97b6/example.capx

any help is appreciated
B
6
S
1
Posts: 22
Reputation: 459

Post » Sun Jul 14, 2013 3:36 pm

Hey jaketakelake. I think you're misunderstanding how the JSON object works. JSON is a format for expressing arrays in a string.

When you tell Construct to "Load from JSON string" you are supplying the value "examplelevel.json". However, this doesn't actually have anything to do with the file in your Files folder. It's just a literal string, so Construct attempts to parse "examplelevel.json" - which isn't a valid JSON string in itself - and unsurprisingly nothing happens.

So, what are your options? You have two as far as I can see. You can use the AJAX object to request a JSON string from a PHP page, and store your levels in a server somewhere. This is a fairly simple solution if you have access to a server.

Alternatively, if you are developing for desktop, you should be able to use Node-Webkit's File IO functions to retrieve the contents of your level.

To reiterate: The Load JSON action requires a JSON string, which right now you are not providing. There is no way that I am aware of to access this file when it is in the Files folder.
B
55
S
12
G
8
Posts: 339
Reputation: 9,364

Post » Sun Jul 14, 2013 5:10 pm

thanks. i understand. do you recommend a better way to load multiple levels?

edit: I tried your first option. I used ajax to request the "examplelevel.json". How do i transfer the data to a dictionary?jaketakelake2013-07-14 20:51:37
B
6
S
1
Posts: 22
Reputation: 459


Return to How do I....?

Who is online

Users browsing this forum: Colludium, dop2000, NN81 and 26 guests