Score API

In order to have scores allocated to the users for your games the website, you need to have the score API.

 

How to apply for the score API.

 

You can apply for the score api in two ways

 
1. During upload, a check box is available.
2. When the owner of the game plays a game, the option to apply for score API will appear in the section "High Scores"

       
Once applied, the admin has to approve this request. On Approval, an email is sent to the developer, in which will be contained the api key for the game.
               

The developer can now start allocating scores for his game. scores can be monitored by the administrator, so fraudulent scores will be removed.

      
                
                
How to Allocate a score to a game

A game file can allocate score to a user, by posting the API KEY and SCORE to portal strikes api handler.
The developer has to edit his game code, and post the score to the API handler wherever you may find it necessary. Make sure the correct API key is used.

 

For AS3 developers

package{
 
    //imports the packages used
    import flash.display.Sprite;
    import flash.net.URLRequest;
    import flash.net.URLVariables;
    import flash.net.URLRequestMethod;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLLoaderDataFormat;
 
    //class to send the URL variables to the server.
    public class Score extends Sprite
    {
        //private attributes.
        private var urlRequest:URLRequest;
        private var gameUrl:String;
        private var api_key:String;
        private var game_score:String;
        private var myVariables:URLVariables;
        private var urlLoder:URLLoader;
    
        //method to send a request to the server.
        public function Score():void
        {
            
        }
        //call this method for sending the values
        public function sendVariables(apiKey:String, gameScore:String, __url:String)
        {
                gameUrl = __url;
                urlRequest = new URLRequest(gameUrl);
                urlRequest.method = URLRequestMethod.POST;
 
                //creates a URL request with URL variables.
                    myVariables = new URLVariables();
                myVariables.api_key = apiKey;
                myVariables.game_score = gameScore;
                urlRequest.data = myVariables;
 
                    urlLoder=new URLLoader()
                    urlLoder.dataFormat=URLLoaderDataFormat.VARIABLES;
                urlLoder.addEventListener(Event.COMPLETE,loadDataFromPhp);
 
                //send the request.
                urlLoder.load(urlRequest)
                
        }
 
        //to load data
        private function loadDataFromPhp(e:Event)
        {
            trace(unescape(e.target.data));
        }
            
     }
    
}

 

You can instantiate the class with the following code


    var someName:Score=new Score;

When you need to allocate a score to a user, place a call to the function as shown below

    someName.sendVariables(API_KEY_HERE, SCORE_HERE, http://portalstrike.com/api/grantScoreApi)

Replace the API_KEY_HERE with the corresponding values obtained from portal strike.

Replace the SCORE_HERE with the score you wish to grant to the player.

 

For AS2 developers

 

// Class to send URL Variables to the server. 
class Score
{
    // Create load vars object 'send_lv' for data transfer
 
    private var send_lv:LoadVars;
    
    // Constructor
    public function Score()
    {
        
    }
    
    // Method for load data.
    public function sendVariables(apiKey:String, gameScore:String, __url:String)
    {        
        send_lv = new LoadVars();
        // Gets the value of API KEY, Game Score and URL
        send_lv.api_key = apiKey;
        send_lv.game_score = gameScore;
        // Sending data to external web application
        send_lv.sendAndLoad(__url, send_lv, "POST");
        // Calls 'checkLoadedData' method on 'onLoad'
        send_lv.onLoad = checkLoadedData;
        
    }
    
    // if data was loaded  
    private function checkLoadedData (success:Boolean)
    {
        // Parse the data returned
        if(success)
        {
            trace(unescape(this.toString()));
        }
        // Display an error
        else
        {
            trace("Error in connection!!");
        }
    }

}

You can instantiate the class with the following code


    var someName:Score=new Score;

When you need to allocate a score to a user, place a call to the function as shown below

    someName.sendVariables(API_KEY_HERE, SCORE_HERE, http://portalstrike.com/api/grantScoreApi)

Replace the API_KEY_HERE with the corresponding values obtained from portal strike.

Replace the SCORE_HERE with the score you wish to grant to the player

General Note :

 

The score obtained by a user for a game, is the  highest score he obtained for that game. The user score details for a game is displayed in the game-play page, in the "High Scores" section.