View unanswered posts | View active topics It is currently Wed Aug 17, 2022 2:35 pm



Reply to topic  [ 2 posts ] 
 Displaying numbers 
Author Message
Junior Member

Joined: Fri Apr 30, 2004 8:22 am
Posts: 1
Post 
hi guys, im completely new to php and require a bit of assistance...

i am creatign a racing game in flash and have created a high scores table to post you best laptimes...

I have got all this working correctly appart from the fact that the score will only post to the decimal place. For example

if you get a time of 01.01.000 then the time will be displayed in the table as 1

how can i make it post the whole score?

the code im using is this...



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")
{

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 ("&");
}
}

?>


anybody's help will be great!!

thanks

John


Fri Apr 30, 2004 8:24 am
Report this post
Profile
Junior Member

Joined: Tue Apr 13, 2004 11:34 pm
Posts: 16
Location: Gresham, Oregon. United States
Post 
Without actually testing it, I guess that your problem is the (int) typecast at the top of the script - Thats going to trim the decimal point of your results.


Fri Apr 30, 2004 9:22 am
Report this post
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.