Post score to database after game over

Get help using Construct 2

Post » Sun Nov 09, 2014 10:22 pm

Hello,

I have discovered this awesome program today and try to get familiar with it. I have successfully programmed tutorial game, but need to test how one things work (and if it is possible) before I will buy full license. How is possible to do that after gameover will be called .php file which will add score to database? I have seen tutorial, which explain this with some buttons. But I need one-time thing.
Simply need to call my php file which is adding score into database once when member reach gameover.

Thanks for help in advance!
B
3
Posts: 9
Reputation: 193

Post » Sun Nov 09, 2014 10:23 pm

Try with WebStorage set game session and then via php file read that session

Hint: Green marker :)

Image
B
6
S
1
Posts: 57
Reputation: 514

Post » Sun Nov 09, 2014 10:37 pm

What should I wrote to value field if name of my score is Score, so in value field should be "&Score&" or ?????
B
3
Posts: 9
Reputation: 193

Post » Mon Nov 10, 2014 9:03 am

Anybody? If I post score via "&Score&", it doesn´t work, how to make it?
B
3
Posts: 9
Reputation: 193

Post » Mon Nov 10, 2014 9:21 am

for the database, you have to make a php:

get a score from CONSTRUCT2 with method "POST" and send the information to the file with AJAX plugin
your file php will connect to your database
you have to make a code who INSERT the value where the ID or USERNAME is, like

"$sql = mysql_query("INSERT INTO `name of database`.`userdb` (`id`) VALUES ('','$idFROMC2');");"

and after this, you have to make another script who asort the score table....

now I'm working, when I get home, if I have time I will post more information.... search on internet how insert data on the database, how connect on the database...etc.... contruct2 have just to send the score or other variables... you have to work with the php... it's pretty simple if you start with the php... there are a lot of tutorial step by step on internet... find a good one, and you can start very good
B
21
S
9
Posts: 298
Reputation: 2,967

Post » Mon Nov 10, 2014 10:24 am

Thank you, but I´m experienced in PHP, that thing about inserting in databse and getting data etc is clear for me as I wrote in my first post. Only thing I have problem is POST score from the game, because I don´t know what to write in which ajax column in game editor :D
B
3
Posts: 9
Reputation: 193

Post » Mon Nov 10, 2014 12:06 pm

Ferda12 wrote:Thank you, but I´m experienced in PHP, that thing about inserting in databse and getting data etc is clear for me as I wrote in my first post. Only thing I have problem is POST score from the game, because I don´t know what to write in which ajax column in game editor :D


ON ajax, select:

Post to url:

TAG (you can use on event of contruct2)

URL (of the php file)

Data: (the variables to send, like, if you have USERNAME and SCORE)

"username="&variableofC2USERNAME&"&"&"score="&VariablescoreonC2

method: "POST"

with this, you will send:
variableofC2USERNAME to username and VariablescoreonC2 to score on your php :)
B
21
S
9
Posts: 298
Reputation: 2,967

Post » Mon Nov 10, 2014 7:34 pm

Ribis wrote:
Ferda12 wrote:Thank you, but I´m experienced in PHP, that thing about inserting in databse and getting data etc is clear for me as I wrote in my first post. Only thing I have problem is POST score from the game, because I don´t know what to write in which ajax column in game editor :D


ON ajax, select:

Post to url:

TAG (you can use on event of contruct2)

URL (of the php file)

Data: (the variables to send, like, if you have USERNAME and SCORE)

"username="&variableofC2USERNAME&"&"&"score="&VariablescoreonC2

method: "POST"

with this, you will send:
variableofC2USERNAME to username and VariablescoreonC2 to score on your php :)


I have folowed your steps but not working. It just change the database column to 0, not reached Score. Name of my variable is score, I have Data column: "points="&Score""

Then php get:
$score = mysql_real_escape_string($_GET['points']);

The database updating works, it change the amount, but to zero, I still think, that It is not posting score correctly :(
B
3
Posts: 9
Reputation: 193

Post » Mon Nov 10, 2014 8:42 pm

Ferda12 wrote:
Ribis wrote:
Ferda12 wrote:Thank you, but I´m experienced in PHP, that thing about inserting in databse and getting data etc is clear for me as I wrote in my first post. Only thing I have problem is POST score from the game, because I don´t know what to write in which ajax column in game editor :D


ON ajax, select:

Post to url:

TAG (you can use on event of contruct2)

URL (of the php file)

Data: (the variables to send, like, if you have USERNAME and SCORE)

"username="&variableofC2USERNAME&"&"&"score="&VariablescoreonC2

method: "POST"

with this, you will send:
variableofC2USERNAME to username and VariablescoreonC2 to score on your php :)


I have folowed your steps but not working. It just change the database column to 0, not reached Score. Name of my variable is score, I have Data column: "points="&Score""

Then php get:
$score = mysql_real_escape_string($_GET['points']);

The database updating works, it change the amount, but to zero, I still think, that It is not posting score correctly :(


you have to set &score without the ""... and if you use GET, you can't use POST....

GET is working on url like myscript.php?username=mynameinC2&score=8238923

you have to change your variable with POST:

$score = mysql_real_escape_string($_POST['points']);

and for more information, you can see if your php generate some error... let me know if you solve that ;)
B
21
S
9
Posts: 298
Reputation: 2,967

Post » Mon Nov 10, 2014 9:16 pm

Thank you very much, I´m idiot :D
Now it is absolutely perfect, thank you so much again!
B
3
Posts: 9
Reputation: 193

Next

Return to How do I....?

Who is online

Users browsing this forum: ST314 and 32 guests