Static Array in Project?

Get help using Construct 2

Post » Thu Aug 01, 2013 6:28 pm

Hi, I've tried to search and read on this, and while some things suggest it possible I could not figure out exactly how.

I would like to save an array of dimensions 30,10,10 in a way to be able to export the project with the saved data available to be read in when it runs on the player's computer.

Is there a tutorial that shows this or an easy explanation?

Thanks
B
5
Posts: 26
Reputation: 277

Post » Fri Aug 02, 2013 1:37 am

You can use the array download action to save the array to a file and then add it as a project file. See this:
https://www.scirra.com/tutorials/328/using-project-files-in-construct-2
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Fri Aug 02, 2013 2:26 am

hmmm, so it does look like it can be done, though I'm still not seeing any clear examples. It seems they suggest at first to store files on a server somewhere on the net and then load them via URL's. Not exactly what I want. Any one able to provide short example or link to tutorial that shows how to actually save an array using this 'dictionary' or 'json' or whatever it is, then how to find that file to put in with the exports? It isn't as simple as 'dictionary - set array to array.tojson' and then when file is in the project that was DL'd you start with 'dictionary - load array.json'? And where do I find the actual file saved as 'array.json'?

The Construct2 manual is pretty good, but when non basic techniques are mentioned, they don't really elaborate on how to use them.
B
5
Posts: 26
Reputation: 277

Post » Fri Aug 02, 2013 10:40 pm

When you have the array filled you can use the array Download action to save it to a file:





When you run that action it will pop up the save file dialog or just save the file directly to your download folder depending on how you have your browser set up:



The file looks like this. It's the array in JSON format (I call it 'level.json' and have notepad set to open .json files. You can call it 'level.txt' or anything really.):


You could also create this file by hand or generate it with code.

Now you can add that file to your project (When you want to change the level just open this file from within C2 and edit it instead of deleting and importing it again.):





Now you need to add the AJAX plugin to the project and request the file:





When the request has completed, the value AJAX.LastData will hold the contents of the file. Use the array 'Load' action to load it into the array.








Example: levelEditorExample.capx (r139)
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Fri Aug 02, 2013 11:25 pm

@ramones

Thank you very much for that. One question, will that array save file get exported with my project so that when it runs elsewhere the program can load it just the same?
B
5
Posts: 26
Reputation: 277

Post » Sat Aug 03, 2013 1:02 am

Yep any files added as project files are exported with the project.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Sat Aug 03, 2013 3:21 am

[QUOTE=ramones] Yep any files added as project files are exported with the project.[/QUOTE]

Awesome! I thank you for helping out!
B
5
Posts: 26
Reputation: 277


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], eochranek, Unconnected and 19 guests