PDA

View Full Version : Highscore with php


APW93
02-13-2011, 03:39 PM
How can I have a highscore system with the variable 'score' by using php.

arkitx
02-13-2011, 03:51 PM
Where is your var score comes from?


<?PHP
$score = 0;
$score+=10 ;
echo $score ;
?>



arkitx

APW93
02-13-2011, 03:58 PM
Where is your var score comes from?


<?PHP
$score = 0;
$score+=10 ;
echo $score ;
?>



arkitx

I have the variable 'score' generated by a game in flash. I want the score to be loaded on start up. And get replaced if the user gets a higher score.

arkitx
02-13-2011, 04:35 PM
Ok, then you have to pass that var into php to save it in a txt file.
then when ever you reopen the game ask php to read the txt file and echo the value from the txt file into flash. continue this as much as you want.


arkitx

bigalc
02-13-2011, 04:37 PM
This could be more complex than you might think. On the server side you're going to need some sort of database (probably MySQL) of users and their scores.

The Flash movie then needs to ask the user to log-in so that their score can be retrieved. PHP can then be used to validate the login and pass the score back to Flash.

When the user's score changes you can then pass the new score back to the database by using LoadVars to run a PHP script which will update the user's score accordingly.

The specifics of how you would do this are more extensive than can be explained on this forum, but you should be able to find all the information you need from http://php.net and the Flash help files (look up loadVars).

mike007
02-26-2011, 04:28 AM
I would just have the php save the file as plain text. Only have one number, the high score in it. Have two php functions, one for reading and one to write the new score. I can post you the php code if you havn't figured it out yet.