TBM_Christopher
Semi-pro Game Dev
- 421
- Posts
- 15
- Years
- Age 31
- Lincoln, NE
- Seen Apr 12, 2018
Hi, I've been trying to write a simple high scores system for my wobsite, and so far I've been somewhat stuck on this. I've adapted the script from the Unity Scripting Reference, but without much luck.
Here's the script I'm using on the Unity end:
For the Perl script, this is what I have:
However, I did a quick test of my game and then checked the database, and no entry had been written. :-| Does anybody here know what the problem would be?
Also, the line, "Debug.Log(download.text);" is returning the error: "Assets/Scripts/ScoreDisplay.js(54,20): BCE0019: 'text' is not a member of 'UnityEngine.WWW'. " Is this related?
Here's the script I'm using on the Unity end:
Code:
function GameOver() {
// Create a form object for sending high score data to the server
var form = new WWWForm();
// Assuming the perl script manages high scores for different games
form.AddField( "game", "MyGameName" );
// The name of the player submitting the scores
form.AddField( "playerName", playName );
// The score
form.AddField( "score", score );
// Create a download object
var download = new WWW( highscore_url, form );
// Wait until the download is done
yield download;
if(download.error) {
print( "Error downloading: " + download.error );
return;
} else {
// show the highscores
Debug.Log(download.text);
}
Application.LoadLevel("GameOver");
}
For the Perl script, this is what I have:
Code:
#!/usr/bin/perl
# The SQL database needs to have a table called highscores
# that looks something like this:
#
# CREATE TABLE highscores (
# game varchar(255) NOT NULL,
# player varchar(255) NOT NULL,
# score integer NOT NULL
# );
#
use strict;
use CGI;
use DBI;
# Read form data etc.
my $cgi = new CGI;
# The results from the high score script will be in plain text
print $cgi->header("text/plain");
my $game = $cgi->param('game');
my $playerName = $cgi->param('playerName');
my $score = $cgi->param('score');
exit 0 unless $game; # This parameter is required
# Connect to a database
my $dbh = DBI->connect( 'DBI:mysql:toybox_gamehs', 'deusexmachina', '-Password Censored-' )
|| die "Could not connect to database: $DBI::errstr";
# Insert the player score if there are any
if( $playerName && $score) {
$dbh->do( "insert into highscores (game, player, score) values(?,?,?)",
undef, $game, $playerName, $score );
}
# Fetch the high scores
my $sth = $dbh->prepare(
'SELECT player, score FROM highscores WHERE game=? ORDER BY score desc LIMIT 10' );
$sth->execute($game);
while (my $r = $sth->fetchrow_arrayref) {
print join(':',@$r),"\n"
}
However, I did a quick test of my game and then checked the database, and no entry had been written. :-| Does anybody here know what the problem would be?
Also, the line, "Debug.Log(download.text);" is returning the error: "Assets/Scripts/ScoreDisplay.js(54,20): BCE0019: 'text' is not a member of 'UnityEngine.WWW'. " Is this related?