Adding a few flash games to your site is always a great way to get visitors to stay on your site a bit longer and even keep them coming back. It’s well known that one of the best ways to keep visitors coming back is interactivity. So why not let your visitors battle it out between each other?
Central Scoreboard with Flash and ASP - Adding player’s scores (Page 3 of 4 )
Next we need a file that will add player’s scores when they are sent. We also need a system to stop users adding scores to the database without actually playing the game. Bring up a new file in your text editor and save it as addscore.asp. This file will be sent variables from the flash movie:
Player – this will be the player’s name
Score – the player’s score
Passcode – this is a variable that makes sure the user is not just accessing the page using their browse
In this file we open up the connection as normal but change the SQL:
.Form("passcode") = "XHjf5" Then
Dim playername playername = "XXX" If Request.Form("player") <> "" Then playername = Request.Form("player") End If playername = (Left(playername, 3))
The “if” around the whole script checks to make sure the variable has sent; if you’re using this on the web make sure you change the variable to something else. It’s important that your scoreboard is protected for adding scores although there is no need to project the script that displays results.
All the script essentially does is insert the values into the database. If no player name is given the script uses XXX. This is because players will need to enter their names and some players won’t bother. There is also a function in the script to stop players having any more than 3 letters giving it an old fashioned arcade feel.
The one problem that could arise in this script is players who enter 1 or 2 character long names. Personally I don’t mind this although if you want to insist on all players having 3 letters you could filter out these players and use the default using a script such as: