C++ Leaderboards
From J2Play
J2Play leaderboards store and list the best scores achieved by the players in the game. To use the leaderboard feature, report the score through the ScoreController interface class.
(Since GDK ver 3.3)
Contents |
ScoreController
Get the ScoreController interface through CGDKInstance, it may return NULL if community hasn't been created.
ScoreController* score = CGDKInstance::GetInstance()->GetScoreController();
if (score)
{
// use score interface
}
Easy highscore APIs
The simplest APIs for one highest score are the easy score APIs
ScoreController::EasySetScore()
ScoreController::EasyGetScore()
Notice:
- By easy highscore APIs, each user only has one record in the specified Leaderboard, it is the best score record of the user.
- EasySetScore only supports submitting one value per score record.
- For only one highest score record per user will be record, any other score achieved by the same user, which less than the best one, will be dropped.
- There are four kinds of Leaderboards: daily, weekly, monthly and all-time, every score submitted by easySetScore will be processed according to aforementioned rules by every Leaderboard individually.
- EasyGetScore will get the toppest score record of specified user, if the score record includes more than one value, it return the first value automatically
- The score type for easy score APIs is J2PLAY_DEFAULT_LEADER_BOARD_SCORE_TYPE implicitly.
Easy scores APIs
Easy scores APIs are a little advanced than the easy highscore APIs. They support an array of values in a score record, as well the assigned score type.
ScoreController::EasySetScores()
ScoreController::EasyGetScores()
Notice:
- EasySetScores supports int[] style score reocrd..
- EasyGetScores will get the toppest score record of specified user. It returns a ScoreRecordSet as result.
- The score record submitted to server will be compared to the existed record value by value in sequence, only the best score record will be stored, others will be dropped.
ScoreRecordSet
The ScoreRecordSet is presenting a score record set as the result of the score get API. It is a list of score record, every record includes username, nickname, message, and an array of score values. You can get the content of score record set by following APIs.
ScoreRecordSet::GetRecordCount()
ScoreRecordSet::GetScoresCount()
ScoreRecordSet::GetScoreValue()
And, the ScoreRecordSet pointer must be destroyed by calling DestroyScoreRecordSet() after using.
ScoreController::DestroyScoreRecordSet();
Raw score APIs
Using raw score APIs to get most flexibility and controlling over score.
Notice:
- Mixing use different sets of score APIs may mess up score record.
Other helpful score interface
Here introduces other APIs in ScoreController interface which is helpful when you want specified score record set.
ScoreController::GetTopScores()
Enabling Leaderboards
To enable leaderboards follow these steps
- 1. Edit your game in the J2Play Management Console and select the Game tab
- 2. Under Integrated features make sure that leaderboards is checked
- 3. Navigate to the Score tab
- 4. For each score type you want to appear in the leaderboard enter in the score type of that score, a human readable label, whether or not higher scores are better, and the desired display format for the score into the very last row of the table
- Note: If you are using ScoreController::EasySetScores() use Record as the score type for the score
- 5. Click the Add button to add the score to the table and click Save when all of the data has been entered
- Please allow up to 30 minutes for the data to appear in the system
