A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Using a Highscore Tutorial

  1. #1
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167

    Using a Highscore Tutorial

    Hi guys,

    I'm using Glen Rhode's highscore tutorial that provides the necessary files to create a highscore system. You can see the tutorial here.

    I have uploaded the scores.php file as it said to, and creating a new directory from here called scores with permission set to 777. It then asked to run a link provided which should display a highscore setup.

    However, when I put the link in my URL I get the following: click!


    The PHP code provided in scores.php is the following, although, the tutorial never makes mention of having to tinker with this:

    PHP Code:
    <?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 ("&");
            }
        }

    ?>

    I know every little of PHP and was hoping for a quick way of implementing a simple highscore system into my quick puzzle game. Can anyone help me out?

    Thanks!

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    this is very old code. Some time in 2002 php was changed so that variables sent from the web do not automatically become php variables but need to be called explicitly

    You would at least need these lines
    Code:
    <?php
    $winscore = $_REQUEST['winscore'];
    $filename = $_REQUEST['filename'];
    $action = $_REQUEST['action'];
    to make the old tutorial work.
    However, I would not like to use this one...
    First question: do you need the ability to maintain more than one highscore list (e.g. for a site that has various games, and each one has its independent scores)?
    If not, just use an explicit filename .... this prevents idiots from attempting to create crap files all over the place

    Musicman

  3. #3
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Well, I hope to make a few simple puzzle games to just hold me over while I'm waiting around on my main project. So I believe I'll be needing to maintain multiple highscores independent from the others.

    I'll try working with the code you gave me, but any different directions that you can suggest are appreciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center