Built in examples: AJAX

Discussion and feedback on Construct 2

Post » Tue Jul 02, 2013 7:36 am

Would love to see some simple built in examples/samples of AJAX in action...

WebStorage might be nice as well...
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Tue Jul 02, 2013 7:59 am

Probably a good idea. :)

Meanwhile, here is a screenshot from one of my projects. It loads array of data from a simple text file(json format):



Here are contents of the text file:

{
"c2array":true,
"size":[5,7,1],
"data":[

[["Bob the Builder"],["He builds things."],[1],[2],[10],[100]],
[["Ben the Builder"],["He builds things."],[1],[2],[10],[100]],
[["Bill the Builder"],["He builds things."],[1],[2],[10],[100]]

]}
vee412013-07-02 07:59:36
B
24
S
8
G
7
Posts: 756
Reputation: 7,242

Post » Tue Jul 02, 2013 8:30 am

Well this is awesome... really, incredibly helpful and explains a ton! I can read about it in the manual all day but until I see it in action like this I am so lost...

This helps make the concept of "tags" make a lot more sense.

I can see how this is going to save me tons of time on my first-run data load...

Where would the .txt files for this be kept?

Is there a way to update the .txt files? That's really the big killer for me.

My app basically collects names from user input and creates an array to hold the names. Being able to export this into any kind of file that I can access with 3rd party software (text editor, Excel, etc) is my goal. I have to ensure that the list of names in the array is stored in a stable data location that I can access if something goes wrong...

Thanks again for the help this is huge!
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Tue Jul 02, 2013 8:33 am

"Where would the .txt files for this be kept?" -- what I meant by this was where do I place the .txt files to be called? Same folder as the app (e.g. same folder as the .exe for a Windows export)?
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Tue Jul 02, 2013 9:49 am

First, you'll need to save your project in project format instead of a single .capx file. This can be done from the menu of construct 2, 'Save as project'.

After that you can create your text file and import it to construct 2 by right clicking projects 'File' folder and selecting 'Import file'.



Now the file will appear in your project folders 'File' folder.



You can now use external editors to modify those files and changes will be reflected in the game every time you load the file :)vee412013-07-02 09:54:03
B
24
S
8
G
7
Posts: 756
Reputation: 7,242

Post » Tue Jul 02, 2013 11:01 am

That is awesome... my project was incredibly complex to accomplish basically the same thing...

Can the game make changes/updates to the files? Or just load them?

This project has a huge list of names... I can always create the list in a comma-delimited format and paste it into a global text variable and split it out into an array on load... I'd still rather use what you've shown me and load the .txt file so I can update it from outside the game then just reload the file as needed.

The list of names can be edited by certain users and my hope is to be able to capture those changes as they are made... ideally to a file I can access. Cleaning up array.Asjson is preferable to nothing!

Thanks for all the help! Between you and rexrainbow I think I'm finally getting a grasp on some AJAX basics. Thank even more for utilizing the "tags" ... that part really confused me as to how you would use it, this is a lot more efficient and slick compared to the nightmare I wrote lol!
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Tue Jul 02, 2013 11:13 am

The game can't change the files in the project, but you can upload a JSON file online (like Dropbox) and use AJAX request URL to obtain the required data. It makes the game more flexible and you can change levels remotely without uploading a new version. For capturing data, I recommend using php and mysql. See this tutorial for more info:
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 02, 2013 11:51 am

Thanks for the push in what's probably going to be the right direction...

Its going to be interesting... I am on a very closed system for where this project will run. No interwebs, probably not even a local network... and I know nothing about PHP and only a tiny bit of mysql... I usually run huge projection systems, this is a little out of my skill set but you guys are the best at helping :)
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Sun Jan 19, 2014 7:25 pm

@vee41

I've been trying to figure this out for days... all the posts just say "Add the file using AJAX, it's easy".

I've been pasting my file into the Files directory, but it never showed up in the Request Project File list.

Your post is the only one that explained that I needed to Import it into the Project first. Thanks so much!! (still useful even 6 months after your post)


B
17
S
5
Posts: 9
Reputation: 1,222


Return to Construct 2 General

Who is online

Users browsing this forum: sinistar99 and 10 guests