Flash Score.setScore
From J2Play
Contents |
Description
Stores score values of the specified score type for the specified user. The score values should be put in parameters[] in a well known order.
Syntax
public function setScore( scoreType : String, ascending : Boolean, numToStore : Number, username : String, message : String, values : Array) : Void;
Parameters
* @param scoreType the score type to group scores by. ** Record: the default value should always be "Record" only change this if you want to submit multiple scores * @param ascending, it can be true or false ** true: if is low scores are better (like golf), ** false: if high scores are better (like baseball) * @param numToStore specifies the number of scores to store per user for this game and scoretype. ** -1: Replace the old score with the new one even if the score is lower ** 0: Cumulative score type add the new value to the previous (i.e. current score is 10 passing 1 will make the new score 11) ** 1+: Store 1 or more high scores for the the user (i.e. passing 1 will store 1 highscore, passing 2 will store 2 highscores, etc...) * @param username specifies the user name for which the score is set or null to store for the current user. * @param message a user supplied message to store with the score (e.g., "I rule!") * @param values specifies the scoring values, it is an array of integers, please don't send decimal score.
Return Value
N/A
Examples
The following examples outline the common usage of the score API.
Store One Highscore
This example updates score type "Record" for the current user. Only the best value should be stored, so the parameter is 1. If the user has posted a better score before, then the score values won't be updated, but if this is the best score for the user, then new value will be stored.
// user scored 5460 points
var points = new Array(5460);
//send the score values
score.setScore("Record", false, 1, j2play.getUsername(), "", points);
Replace the Highscore
This example updates score type "Last Score" for the current user. Only the last value should be stored, so the parameter is -1. The current values will be replaced with new ones.
// user scored 5460 points
var points = new Array(5460);
//send the score values
score.setScore("Last Score", false, -1, j2play.getUsername(), "", points);
Cumulative Highscores
This example updates score type "Totals" for the current user which contains user's lifetime points and number of games. The current value will be incremented by new points the user scored.
// user scored 5460 points and played 1 game
var points = new Array(5460,1);
//send the score values
score.setScore("Totals", false, 0, j2play.getUsername(), "", points);
Multiple Highscores
This example demonstrates how to store multiple highscores for a single game. To submit multiple scores all you have to do is to pass in different names for the first parameter of the API, the scoretype parameter. (i.e. bellow we're passing "Score1" and "Score2").
NOTE: Please contact developer@j2play.net to enable the multiple scoretypes for your game. In the email include the API calls. ( i.e. score.setScore("Score2", false, 1, j2play.getUsername(), "", pointsTwo) )
// user scored 5460 points and played 1 game
var pointsOne = new Array(5460,1);
var pointsTwo = new Array(8742,2);
//send the score values
score.setScore("Score1", false, 1, j2play.getUsername(), "", pointsOne);
score.setScore("Score2", false, 1, j2play.getUsername(), "", pointsTwo);
