Flash ScoreManager.getScore

From J2Play

Jump to: navigation, search

Contents

Description

Gets a set of scores of the specified score type and in the specified game.

Syntax

public function getScores(
  scoreType : String, 
  ascending : Boolean, 
  firstUser : String, 
  firstRank : Number, 
  limit : Number,
  callback : Callback) : Void;

Parameters

* @param scoreType the type of the scores
* @param ascending true if low scores are better (like golf), false if high scores are better (like baseball)
* @param firstUser A username. The received scores will start at this user's best score.
* @param firstRank The received scores will start at this rank.  If firstUser is defined, this argument is ignored.
* @param limit the maximum number of scores to return, or -1 for all scores.
* @param callback the callback to call on successful scores retrieval. The callback function will be called
*     with an array of IScore elements.

Return Value

N/A

Score Type

For basic Leader Board, the score type is "Record"; and for Daily/Weekly/Monthly Leader Board, the score type is "SCORE_DAILY_Record"/"SCORE_WEEKLY_Record"/"SCORE_MONTHLY_Record".

Examples

Here is the example to restore saved game score information: First, makes a function to handle the result

function onScore(scores : Array) : Void
{
  // 'values' is array of IScore elements
  // for example, you gonna access first score item
  var score : IScore = scores[0];
  var score_values : Array = score.getValues();
  // the score_values is the array you put into the setScores()
  // you can unserialize from the score_values to get all score values to variables
}

Secondly, create a callback object for onScore

// make a callback object
// if onScore is a class member function, you should passed in object a instance of the class (e.g. this);
// otherwise, you can ignore this parameter
var callback : ca.j2x.flash.Callback = new ca.j2x.flash.Callback(onScore, object);

Then, call getScore by different score request

  • This example gets top 10 scores (10 scores from rank 1 to rank 10) of score type "Record" in game
 scoreManager.getScores("Record",false, null, 1, 10, callback);
  • This example gets top score of type "Record" starting from player "jon.j2play".
 scoreManager.getScores("Record", false, "jon.j2play", 0, 1, callback);

If getScore succeeds, it will callback the onScore function with the array of score values.

Personal tools