Game Scoring System Bug

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ging
Forum Newbie
Posts: 1
Joined: Tue Feb 03, 2009 3:00 pm

Game Scoring System Bug

Post by Ging »

Hi All

I have developed a game for Facebook in PHP. The original scoring system was 1000 per level. It is now level 1 = 1000, level 2 = 1000 + 2000, level 3 = 1000 + 2000 + 3000 ect. The code i am using is below but for some reason if the points required are above 6000 then one points extra means they get the next level. example 6000 - 9999 points should be level 4 but if the user has 6001 they get level 5. It works correctly before 6000 points. Any ideas would be great. Thanks

Code: Select all

 
 
$playerStatsUpdateQuery = "SELECT * FROM players WHERE userID = ".$user." ";
        $playerStatsUpdateResult = mysql_query($playerStatsUpdateQuery, $connection);
        
        WHILE ($playersRow = mysql_fetch_array($playerStatsUpdateResult))
        {
            $playerLevel = $playersRow['playerLevel'];
            $playerPoints = $playersRow ['playerPoints'];
        }
        
        $targetLevel = $playerLevel + 1;
        $runningTotal = 0;
        $count = 0;
    
        DO
        {
            $runningTotal = $runningTotal + ($count * 1000);
            
            IF ($runningTotal > $playerPoints)
            {
                ECHO $count;
                BREAK;
            }
            $count ++;
        }
        WHILE ($runningTotal < $playerPoints);
        
        ECHO "</BR>";
        ECHO $runningTotal;
        ECHO "</BR>";
        ECHO $playerPoints;
 
 
Post Reply