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!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.