1. Post #1
    WhiTAkeR's Avatar
    December 2009
    107 Posts
    Hey I'm wondering if anyone knows a good tutorial or knows how to make a leader board for a game and would care to explain how to do it? I would like it to upload to a web server so there is a multi player aspect in the game. I have found some tutorials where the game is in the same location as the leader board php script but as i ultimately want to compile it as an iPhone app and see if it works this isn't an option.

    Thanks to anyone who has some information.

  2. Post #2
    Gold Member
    Naelstrom's Avatar
    June 2010
    2,686 Posts
    When sending data to the php script, i beleive you can put the direct url.

    instead of
    MySendVars.send("myphp.php","_self");
    use
    MySendVars.send("http://myserver.com/myphp.php","_self");

    I'm unsure however. Another way is to have your game .swf on a server with the php script. And compile a swf for the phone that downloads and loads the .swf from the server.

  3. Post #3
    Gold Member
    AaRoNg11's Avatar
    May 2005
    564 Posts
    I did this a little while ago in an assignment for University. The easiest way to do this is to have a PHP / MySQL backend which the flash sends the score to. This is by no means secure, and very easy to cheat for somebody with even a small amount of networking knowledge. I also modified this to remove a lot of dependencies, so it might not work without some modification.

    Code:
    var Website:String = "http://yourwebsite.com/scoreboard/savescore.php";
    var Completed:Boolean = false;
    
    function saveScore(score:Number)
    {
    	var url:String = Website + "?username=" + Username + "&score=" + score + "&gameid=2";
    	var myLoader:URLLoader = new URLLoader();
    	try
    	{
    		myLoader.load(new URLRequest(url));
    		myLoader.addEventListener(Event.COMPLETE, onLoaded);
    	}
    	catch (error:Error)
    	{
                    Completed = false;
    		// Print error message here
    	}
    }
    
    function onLoaded(e:Event):void {
            // Score saved. 
            Completed = true;
    }
    And here is some PHP (this is probably insecure, I didn't do a lot of input sanitation as it was just for an assignment and security wasn't an issue).

    savescore.php
    Code:
    <?php
    include("config.php");
    
    $con = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
    @mysql_select_db($db_name, $con) or die(mysql_error());
    
    $name = mysql_real_escape_string($_GET['username']);
    $score = mysql_real_escape_string($_GET['score']);
    $gameid = mysql_real_escape_string($_GET['gameid']);
    
    
    $query = "INSERT INTO highscores (Username, GameID, Score) VALUES('$name', '$gameid', '$score')";
    mysql_query($query) or die(mysql_error());
    
    echo("success");
    
    
    ?>
    scores.php (to view the high scores)

    Code:
    <?php
    include("config.php");
    
    $gameid = $_GET['gameid'];
    
    $query = "SELECT * FROM highscores WHERE GameID = '$gameid' ORDER by score DESC";
    $con = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
    @mysql_select_db($db_name, $con) or die(mysql_error());
    $result = mysql_query($query) or die(mysql_error());
    
    echo "<html><body>Click <a href=\"./index.php\">here</a> to go back.</br></br></body></html>";
    
    $index = 1;
    
    while ($row = mysql_fetch_assoc($result)) {
    	$id = $row['GameID'];
    
    	if($id == $gameid)
    	{
    		$username = $row['Username'];
    		$score = $row['Score'];
    		echo($index . " - " . $username . " with score " . $score . "<br/>");
    		$index++;
    	}
    }
    
    ?>
    and config.php

    Code:
    <?php
    $db_host = "localhost";
    $db_user = "root";
    $db_pass = "yourmysqlpassword";
    ?>
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Friendly Friendly x 2 (list)

  4. Post #4
    WhiTAkeR's Avatar
    December 2009
    107 Posts
    All right thanks guys ill route through the code and give it a try

  5. Post #5
    Hearts
    Agent766's Avatar
    July 2007
    3,179 Posts
    If this is going to be an iPhone app, doesn't Game Center provide a leaderboard?

  6. Post #6
    WhiTAkeR's Avatar
    December 2009
    107 Posts
    I cant find a way to implement that or openfeint etc when making it through flash.

    its fine on a mac and in c# but cant find a way to do it this way.