Fill Array and Save as JSON

Get help using Construct 2

Post » Tue Jul 16, 2013 3:44 am

I've been reading the tutorials on arrays, and have looked at the FAQ about arrays, but I still seem to be missing how they work in Construct 2. I am trying to save a list of animation frames to an array and download it via JSON but have had no success.

In this example, I am painting terrain (hold SPACE and left click on the terrain you want to paint in the menu, then just left click on the map) and I want to save it with the "`" key, and download it by pressing TAB. This is just a test for something later, but I can't seem to get the saving part right. I'm not sure how Construct iterates over an array.

Example capx: Capx

Any help will be greatly appreciated.
B
7
S
2
Posts: 39
Reputation: 953

Post » Tue Jul 16, 2013 10:23 am

Watch this tutorial I made last month, this should give you some ideas.
https://www.scirra.com/tutorials/585/how-to-make-an-ingame-costume-made-level-editor
B
14
S
5
G
4
Posts: 107
Reputation: 4,788

Post » Tue Jul 16, 2013 1:09 pm

I have looked at your tutorial before posting, but as you state at the beginning of your tutorial, it is not for absolute beginners. It seems that when it comes to arrays in C2, I am an absolute beginner.

I know in other languages, I would:

//Loop
For X in Width:
For Y in Height:
Array[X,Y] = Tile.Frame
//End Loop

But I cannot seem to figure out how to do this properly in C2.
My array is always full of 0's.
B
7
S
2
Posts: 39
Reputation: 953

Post » Tue Jul 16, 2013 3:41 pm

I've been having the same problem. Arrays are so much more straight forward in programming languages compared to c2. I use dictionaries instead
B
2
Posts: 1
Reputation: 152

Post » Tue Jul 16, 2013 3:58 pm

Can you give me an example that uses dictionaries instead?
B
7
S
2
Posts: 39
Reputation: 953

Post » Tue Jul 16, 2013 10:39 pm

After some Trial and error, I have been able to get a dictionary to store the data correctly.

Keyboard: On key pressed:
-+System: For each TerrainTile: Dictionary: Add Key"Tile"&TerrainTile.UID with value TerrainTile.AnimationFrame

I tried this same method with Arrays with no success. I'm not sure why it won't work, but I guess I'll move on to using dictionaries barring one more thing.

I am able to download the data.json file, but how do I go about loading it? I've looked at the project files tutorial, but I don't see an example on how to load the saved dictionary. Can someone point me on how to load a .json file to a dictionary with a project file?

I'm not interested in keeping the file in webstorage.
B
7
S
2
Posts: 39
Reputation: 953


Return to How do I....?

Who is online

Users browsing this forum: Ajbael, jmiller4180 and 9 guests