Jump to content

Simple High Score List (Something seems wrong)


coollog

Recommended Posts

I was making this simple high score list, and I came across a problem, here's my code:

<img src="loadingbar.png"/><br/>
<center><h2>High Scores List</h2></center>
<?
$dir=dir("C:\Users\coollog\Desktop\Meh Productions\american revolution\Server");
$arr=array();
while (($file = $dir->read()) !== false){
$path_info = pathinfo("C:\Users\coollog\Desktop\Meh Productions\american revolution\Server\\".$file);
if($path_info['extension']=='acc'){
	$ini=parse_ini_file('C:\Users\coollog\Desktop\Meh Productions\american revolution\Server\\'.$file);
	if(isset($_ini['score']) and (real)($ini['score'])>1000){
		$arr[basename($file,'.acc')]=$ini['score'];
	}
}
}
asort($arr,SORT_NUMERIC);
$n=1;
print_r($arr);
foreach($arr as $key=>$val){
echo '#'.$n.' '.$key.' ('.$val.')<br/>';
$n++;
}
?>

 

This won't have any values go through the check of if(isset($_ini['score']) and (real)($ini['score'])>1000)

 

But when I change the code to this, there are errors of unknown indexes of score, but it still displays the right ones:

<img src="loadingbar.png"/><br/>
<center><h2>High Scores List</h2></center>
<?
$dir=dir("C:\Users\coollog\Desktop\Meh Productions\american revolution\Server");
$arr=array();
while (($file = $dir->read()) !== false){
$path_info = pathinfo("C:\Users\coollog\Desktop\Meh Productions\american revolution\Server\\".$file);
if($path_info['extension']=='acc'){
	$ini=parse_ini_file('C:\Users\coollog\Desktop\Meh Productions\american revolution\Server\\'.$file);
	if((real)($ini['score'])>1000){
		$arr[basename($file,'.acc')]=$ini['score'];
	}
}
}
asort($arr,SORT_NUMERIC);
$n=1;
print_r($arr);
foreach($arr as $key=>$val){
echo '#'.$n.' '.$key.' ('.$val.')<br/>';
$n++;
}
?>

 

Do you know what's wrong?

 

And if you could optimize my code, that would be awesome!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.