Leaderboard for Games
-
Description
In many single-player games, the goal is to achieve a high score (such as collecting the most gems) or complete a task in the shortest time (such as jumping through some obstacles).
For such games, you can show a leaderboard with the top-ranking players and their performances. That’ll make the game more interesting.
Record a Player’s Score
To store the score of a player, you can use the following block in the “Game” extension:
It takes one input, which is the “score” of the current player. This should be a number value since it will be used to rank between different players. For example, it can be the number of seconds the player used to complete the challenge, or the total number of points or coins the player has gained in the game.This value will be stored in the CreatiCode server, so it will be available even if that user closes the browser page or logs off. A user can play the game multiple times, and all the scores will be stored.
Show the Leaderboard
To show the leaderboard among all users who have recorded their scores, you can use the following block:
This block takes 4 input parameters:- Ranking Method: you can specify to show those players with the lowest scores (smallest numbers) or the highest. For example, if the game’s goal is to do something in the shortest amount of time, then you should show the players with the “lowest” scores.
- Number of Rows: You can decide how many players to list in the leaderboard. If a game has a lot of players, then it makes sense to show a longer list, which will encourage more players to try to compete in the game.
- Header and Background Color: you can customize the colors of the leaderboard. Note that the text is always in white, and the current user is always in green. Below is an example:
Hide the Leaderboard
To hide the leaderboard, the user can click the “x” button on the top right corner of the leaderboard. However, you can also close the leaderboard use the following block: