Loading multiple json files to a single array

Get help using Construct 2

Post » Sun Apr 21, 2013 4:46 pm

Hi everybody,

I am generating [edit: MANUALLY] levels of my game and store them as json files. After I prepared them all, my goal is to load all information of these levels to an array and use them in game. I have tried this method for first level and it worked. But I can't find the right way to do this for multiple levels. For example I have several json files now but I don't know how to load them all to my array. How can I do that?

If this explanation is not clear enough please let me know.

here is the capx

and here is what my levels will look like




Thanks in advance.ebrar2013-04-22 11:42:55
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Sun Apr 21, 2013 7:04 pm

I think your best bet would be to create new instances of the array object, and then load it.
You can then reference additional arrays by variable or its object(index).
There are several advantages to using instances such as "for each", and even containers.
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Sun Apr 21, 2013 8:34 pm

thank you @newt.

I'll try. But there will be plenty of array instances then. Because i am planning to make hundreds of levels. At least aproximately two hundred. Is that a problem?

And i didn't understand "There are several advantages to using instances such as "for each", and even containers." part, sorry. Can you explain it a little bit, if you don't mind?
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Sun Apr 21, 2013 9:13 pm

You be the judge: link
Each sprite has an array attached via container.

I think your only issue would be loading the array... that is if there is a large file to load.

As for for each. As you can imagine it would work the same as it would for sprites or other objects.
That is to say picking each of the instances and in a specific order.
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Sun Apr 21, 2013 9:21 pm

thanks again @newt :)
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Sun Apr 21, 2013 10:05 pm

Is it possible to fill these array instances (with different json strings) in one single event or i must use as many events as number of array instances?

I couldn't figure out how.
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Sun Apr 21, 2013 11:47 pm

Well I wouldn't try to download 200 files all at once so your best bet is to create a counter variable, and increase that variable each time a download completes.
You can use that like dowload "yourfile"&variable&".json".
Of course you would have to name your json files accordingly.
Then when one download completes add to the variable.
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Mon Apr 22, 2013 9:50 am

thank you so much @newt. great help.

edit: Sorry, i misunderstood. Don't I try to upload (and fill the arrays), instead of download? I already can download the files manually, but can't upload them.ebrar2013-04-22 09:57:08
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Mon Apr 22, 2013 4:04 pm

Ok, um ....lets call it import.
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Mon Apr 22, 2013 5:00 pm

Finally I found this tutorial :D

awesome tutorial

and thank you too @newt.ebrar2013-04-22 17:00:58
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Next

Return to How do I....?

Who is online

Users browsing this forum: selaus and 0 guests