How do I write a simple data on my server.

Get help using Construct 2

Post » Fri Jun 23, 2017 4:13 pm

Hello (excuse my english),

When a button is clicked I would like to write a simple data on my server.
For example when a guy clicks on a button of the game it buys an armor and this sends a data on the server in an array or file.

What is the simplest method with construct 2 tools ?

Thank you
B
12
S
3
Posts: 147
Reputation: 2,026

Post » Sat Jun 24, 2017 9:45 am

No idea ?
B
12
S
3
Posts: 147
Reputation: 2,026

Post » Sat Jun 24, 2017 8:29 pm

Thank you ;)
B
12
S
3
Posts: 147
Reputation: 2,026

Post » Sat Jun 24, 2017 8:49 pm

You are looking for the AJAX object. It allows GET and POST requests:

https://www.scirra.com/manual/107/ajax

In my experience, there are 2 gotchas:
1. Remember to properly escape any quotes "".
2. The format for sending POST data is the same as for GET. In the C2 manual it says:

Post to URL
Send a request with data to a URL and retrieve the response. A tag is provided to match it up with the On completed, On progress and On error triggers. Construct 2 does not automatically URL encode the post data - use the URLEncode system expression to ensure the data is in the correct format for posting. Note post data is in the same format as a query string, e.g. "foo=1&bar=2". The method can also be specified: by default it is POST, but for some APIs you may need to change this to PUT, DELETE or another HTTP method.
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
47
S
13
G
20
Posts: 371
Reputation: 14,445

Post » Mon Jun 26, 2017 5:11 pm

Thank you cjbruce for your answer.

Think otherwise that it is possible to write in a database given mysql ?
B
12
S
3
Posts: 147
Reputation: 2,026

Post » Tue Jun 27, 2017 2:20 am

@chrislechat

Yes, use AJAX to send data to a PHP script on your server. The PHP script can read from and write to a mysql database.
There are tutorials to help you get started.
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Tue Jun 27, 2017 7:07 am

Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Tue Jun 27, 2017 3:22 pm

B
12
S
3
Posts: 147
Reputation: 2,026

Post » Tue Jun 27, 2017 5:25 pm

Yea, like that post (and others have said), you have to use some messaging protocol (HTTP AJAX, WebSockets, etc.) to pass information back to a server program which writes it to a database. PHP is the easiest server-side language to learn.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Tue Jun 27, 2017 7:53 pm

other good example for ajax beginner :

https://www.youtube.com/watch?v=Ez89MXXpOBI
B
12
S
3
Posts: 147
Reputation: 2,026


Return to How do I....?

Who is online

Users browsing this forum: DharmaOne, ezgaming420, JaredX and 11 guests