- Forum
- General Help
- Games
- [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] [
-
Flash Developer on a break
v1.3
v1.3 changes November 26, 2002: _root.add_pass in the AS that inputs new data into the database changed to _root.pass.
__________________________________________________ ________________
Ok... Lets get started. This is my first tutorial, so enjoy!
http://www.ssj-games.com/tut/highscore_tut.zip
Highscore Tutorial
One of the little things for a nice Flash game is a highscore list. It's making people to go back to your game and play it again to win from the competition. It's a way of competition and interactivity between the players to do their best and win as much points as they can.
Things you need
1. A webserver enabled with PHP and MySQL.
Almost all unix/linux webservers have these two, because they are free for everyone. If you don't know if you have PHP4/MySQL enabled, contact your Hosting Company.
2. Notepad.
Or a similar text editing program.
3. A FTP program to upload your files.
CuteFTP or WS_FTP are two examples.
4. The files that come with this tutorial. (highscore_tut.zip)
5. Your nice Flash game.
Duh..
The first few things.
Open '_data.php'.
This is rather important. You need to change a few things here. You need to input the right usernames/passwords/game name/other things.
You will have to change at least numbers 1 to 6. The numbers 1-3 are the few things you need to enter to make contact with the MySQL database. You've got those from your Hosting Company. If not, ask them.
7-14 are optional, they don't need to be changed to get it all working. All things are rather straigtforward.
Upload _data.php/get_score.php/install.php/new_score.php to your website's root directory.
Run the install.php script. When it sais 'Done..', you can delete the install.php file from your website.
Done.
Why PHP/MySQL?
PHP, PHP Hypertext Processing is a free server-based scripting language that is free and provided by a lot webserver/hosting companies. Other than that, it's a very fast language, faster then ASP(from Micro$oft). MySQL is the perfect database partner for PHP. Together they can be fast and above all secure.
Caching
You will notice that sometimes I have added a random variable. This is to prevent caching. It's a common problem of using PHP in combination of flash. To add a random number to the url, you make sure the output of the script is retrieved from the server instead of your hard-drive.
Adding new people to the scores.
Ok, now we are going to start with the Flash part.
When you want to send your highscores from Flash to the MySQL server, you'll need this Actionscript:
Code:
_root.pass = "{same as $add_pass in _data.php}";
_root.name = _root.variableYouUsedInTheGameForThePlayersName;
_root.score = _root.variableYouUsedInTheGameForThePlayersScore;
somevar = random(9999);
loadVariablesNum("new_score.php?" add random(999), 0, "POST");
That's it! The PHP script itself makes sure the player gets added to the database and all other things you don't need to worry about.
Showing the Highscore in Flash.
This is rather easy. Make 10 variable text boxes in a column.(Or the number you used in the _data.php file as $st_size.) These dynamical text boxed are named 'name1' to 'name10'. (Or different, again corresponding to the Standard Size inputted in _data.php.)
Then make 10(Or blab, bla, you know..) dynamical variable text fields next to each corresponding text box called 'score1' to 'score10'.
I am not taking this anyfurther, but you can understand that you can make the looks of your Highscore list somewhat nicer than standard.. ;)
Now use the following Actionscript code to load the variables from the database back into Flash:
somevar = random(9999);
loadVariablesNum("get_score.php?flash=1&" add random(999), 0);
Now the variables get loaded into the _root. But if you have your Highscore list in a movieclip, you should use this code:
somevar = random(9999);
loadVariables("get_score.php?flash=1&" add random(999), "_root.scoretableOrAnyOtherMCname");
The location of the Flash game's SWF file and the location of the Highscore scipts must be at the same domain. (And in these Actionscript code, it must be in the same folder as well.) This is a standard security feature from Macromedia Flash. It can't be changed, live with it.
Including the Highscore list on your webpage.
It is possible to include a HTML highscore list on your webpage. This is realy nice for your site's visitors.
Your page where you want it to show must be a PHP page as well. We take 'index.php' as an example. The $dis_file variable in _data.php must be the same as this page. Now, where ever you want the Highscore table to appear on your page, you include this:
You can change some graphics from the HTML table in _data.php if you want, but look out to only use ' in the code instead of ". That is VERY important.
Ending
Well, that's about it. You can use this to make your own nice Highscore for every game you want.
If you have any comments, questions or suggestions, you can email me at jeroendenhaan@yahoo.com, or visit my site at http://www.ssj-games.com(What comes online very soon..^^)
That's it. If you encounter any problems or so, respond please..
Jeroen
[Edited by jeroen84 on 06-02-2002 at 06:42 AM]
Last edited by jeroen84; 11-26-2002 at 09:06 AM.
-
Flash Developer on a break
And if someone wonders why the table looks so much like the one from Glen... It's just because I used his HTML code from his table. I was too lazy to make my own after scripting all of the PHP. (Can ya blame me?)
However, if you want to know. You can change the table with editing the _data.php file.
This part:
// HTML Table Properties (Use ' in the html code instead of ".)
//10. Top Font properties
$t_font = "<font color='#FFFFFF' face='Arial, Helvetica, sans-serif'>";
//11. Main Font properties
$m_font = "<font color='#750000' size='2' face='Arial, Helvetica, sans-serif'>";
//12. Table Properties
$table_prop = "<table cellpadding='2' cellspacing='2' border='0' width='152'>";
$table_width = "152";
//13. Top Row Color
$t_color = "#000033";
//14. Main Rows Color
$m_color = "#666666";
Oh, and if you want to see an example:
http://www.ssj-games.com/tut/index.php
-Jer'ul
-
Flash Developer on a break
Ok, I've send the tutorial to the Flashkit Tutorial section.
Come on people... Where are ya response? All stuck in the other thread?
-
Elvis...who tha f**k is Elvis?
Hey Jeroen, I don't have the time to go through all of that...I'm at work! Looks good though! I'll look into it later
-
Senior Member
Originally posted by jeroen84
One of the little things for a nice Flash game is a tutorial. It's making people to go back to your game and play it again to win from the competition.
lol
every Flash game should have tutorial
But seriously, thanks jeroen, good work.
-
Elvis...who tha f**k is Elvis?
How's 'bout the "YOU CAN ONLY HAVE 1 SCORE ON THE BOARD"-thingie...that's what I really missed in Glen's version!
-
Flash Developer on a break
tonypa -Hey.. I had to think of some introduction.
phreax -What exactly do you mean? That there can be only one person on the Highscore list? That can be modified in the _data.php file. Just change the $st_size and $sec_size variables.
Or do you mean that a person can only BE on the list one time and then improve his own score? (Aka unique names?)
That is also modiefied in the _data.php file.
Just put the $u_user variable to 1. (This is already standard.)
Btw, Glen's version is hackable. Everyone can CLEAR the table if he wants.
-
Elvis...who tha f**k is Elvis?
Cool, thanks Jeroen, I am gonna try it out later when I get home Yeah I realise that Glen's version had these small security issues but since I couldn't do it myself, his was the best alternative! ...and yes unique names on the board was exactly what I meant...man I gotta speak some more english!
-
Flash Developer on a break
Great. English isn't my primary language as well.
This is to all: I hope you all like it.
-
thanks
I will test it tomorrow with my new game: On Ice
Thanks for the time putting all files and code together. I appreciate it!
TB
-
Flash Developer on a break
-
GamerGirl
Great!
I finally found a host that supports php, so I'll try it, end let ya know what I think. Looks good though!
applauds..
-
Flash Developer on a break
/me bumping this
Does someone know how long you have to wait before you're mailed back after you've send a tutorial with the Flashkit Tutorial submissions form?
Maybe I should resend it... :-/
-
Flash Developer on a break
Bumping this again, 'cause Highscores are mentioned a lot these last days..
I've changed the text a little and fixed a few minor things in the php scripts.
Jeroen
-
i'm bumping this thread because it is so useful!
-
bumping. THanx I needed one of these.
-
Flash Developer on a break
I noticed that the .doc file in the zip file was out-dated. Some people got confused by it. The zip file on my server is now updated.
Note: Do NOT use the tutorial from me in the tutorial section about Highscores. It's the old one. I emailed the administrator with the question if he could update it a few weeks ago, but I guess he's busy.
Anywayz, I hope the tutorial is still clear to all of you and you are still using it.. ^_^
Ciao -Jeroen
-
Bump-ah-dee-bump
great thanx a lot = )
bumping aswell, iv seen 4 mentions o highscore tables in the last 2 weeks = )
-
_
I just learned what "bumping" means. Great job on this php!
-
Flash Developer on a break
UnderTheSun - You are still experiencing problems? If you do, what version of PHP are you using?
You can check with making a file with only <?php phpinfo(); ?> in it.
| "Keep Flashing!"-Jeroen
PHP multiplayer? Check this thread: PHPgateway
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|