-
Senior Member
Scoretable help
Hi all,
A few years back, I created a game that used the Glen Rhodes scoretable tutorial on this site. However, it seems that the PHP is now outdated and wont work. Can someone help me convert the scores.PHP code so that it'll work?
Cheers
[PHP]<?php
$winscore = (int)$winscore;
// Create a Blank File if it doesn't already exist
if (!file_exists($filename))
{
$file=fopen($filename, "w");
fclose ($file);
}
// Read the file in
$oscores = file ($filename);
$numreadin = count($oscores);
// Break out the data into a new 2-d array called $tscores
for ($i = 0; $i < $numreadin; $i++)
{
$g = unserialize($oscores[$i]);
$tscores[$i][0] = $g[0];
$tscores[$i][1] = $g[1];
}
// Fill in any missing data with none/0
for ($i = $numreadin; $i < $scoresize; $i++)
{
$tscores[$i][0] = 0;
$tscores[$i][1] = "none";
}
// Process the actions
// Insert a score/name
if ($action == "INSERT")
{
// Add name to end of list, and sort
$tscores[$scoresize + 1][0] = $winscore;
$tscores[$scoresize + 1][1] = $winname;
rsort ($tscores);
$file=fopen($filename, "w");
// Write them out
for ($i = 0; $i < $scoresize; $i++)
{
$st = serialize($tscores[$i]) . "\n";
fputs($file, $st);
}
fclose($file);
}
// Clear the list
if ($action == "CLEAR")
{
$k[0] = 0;
$k[1] = "none";
$ser = serialize($k);
$file=fopen($filename, "w");
for ($i = 0; $i < $scoresize; $i++)
{
$st = $ser . "\n";
fputs($file, $st);
}
fclose($file);
}
// Process the OUTPUT options
if ($viewtype == "HTML")
{
// HTML PAGE CREATED HERE
?>
<table cellpadding=2 cellspacing=2 border=0 width="152">
<tr align=center>
<th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">#</font></th>
<th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Name</font></th>
<th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Score</font></th>
</tr>
<?
for ($i = 0; $i < $scoresize; $i++)
{
echo ("<tr bgcolor='#666666' align='center'><td><font size='2' face='Arial, Helvetica, sans-serif'>");
echo ($i + 1);
echo ("</font></td><td><font size='2' face='Arial, Helvetica, sans-serif'>");
echo ($tscores[$i][1]);
echo ("</font></td><td><font size='2' face='Arial, Helvetica, sans-serif'>");
echo ($tscores[$i][0]);
echo ("</font></td></tr>");
}
?>
</table>
<?
}
// FLASH DATA CREATED HERE
if ($viewtype == "FLASH")
{
for ($i = 0; $i < $scoresize; $i++)
{
echo ("NAME" . $i . "=");
echo ($tscores[$i][1]);
echo ("&SCORE" . $i . "=");
echo ($tscores[$i][0]);
echo ("&");
}
}
?>
-
Senior Member
Alternatively, if you could just point me in the direction of a different script tutorial (preferably PHP), that would be great.
-
Pumpkin Carving 2008
http://www.egoant.com/tutorials/tut1.php
Best one I've ever used. I still use it for all my games.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Senior Member
Cheers for that. However, I don't have MySQL on my server. What I really want is a PHP only scoretable. I've searched this site but I can't find one anywhere (other than the now obsolete Glen Rhodes one). Maybe I'm not looking hard enough!
-
Game Player - Developer
Yeah
I'm also looking for a simple score table in PHP
"I love to make them as I love to play them"
-
Senior Member
Originally Posted by scheletro
Yeah
I'm also looking for a simple score table in PHP
If you find one, let me know, because I'm pulling my hair out here!! I'm sure someone who new a little about PHP could tweak the Glen Rhodes one on this site to get it working. However, I know nothing about PHP!!
-
Senior Member
Originally Posted by ImprisonedPride
Well I signed up for some hosting with mysql and it doesn't seem to work!! The example game on his site doesn't even work correctly - it says 'error sending score to server'.
All files were created correctly from the install php file but the score table itself doesn't seem to work. Can someone test it and see if there is something wrong with the tutorial or if it is just me!!!
-
Game Player - Developer
"I love to make them as I love to play them"
-
Pumpkin Carving 2008
That is by far the simplest scoreboard tutorial I've used to get working scoreboards. Just make sure you are using the install.php and pasting the exact code it gives you. If there's still a problem connecting to the server, it sounds like you aren't giving the script generator the correct passwords/usernames/dbnames etc. etc.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
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
|