User Tools

Site Tools


developer_center:developer_editor:script:basic_rankings

[Script component] Basic leaderboard

The goal of this script component is to allow the map developer can easily have the leaderboard feature on their map. Please feel free to give feedback or report bugs or feature requests.

Feature of this leaderboard script component

  • 1. Simple and easy to integrate into your map (less than 3 minutes to integrate it into your map).
  • 2. It will automatically upload and download the top 10 from the leaderboard and update the UI for you.
  • 3. Can show the player's name in both single-player rooms, multiplayer rooms, and cloud server rooms.

Note: It will update data every 12 seconds. (this is for the safety of the server.)

Requirement for your map before use

  • 1. Create the Leaderboard variable on your map.

  • 2. Create the player's score variable on your map. (Every time the player makes the score, you have to update this player's variable.)

  • 3. Create a custom UI to display the leaderboard.

How to use (3 mins)


Download the file and paste it into your map (into the UI's script)


Beware, do not paste in 1 line like this. This is wrong.

This is correct

  • 1. Modify the script, and change line 2 to be your leaderboard name.
  • 2. Modify the script, and change line 1 to be your player's score name.

  • 3. Modify the ID of the custom UI element. If you don't know how to get the ID of the custom UI, please see the video. parkour_demo.mp4 How to change the UI' ID
    • 3.1. Modify the script, and change line 3 to be your UI' ID
    • 3.2. Modify the script, and change it to be your UI ID (name)
    • 3.3. Modify the script, and change it to be your UI ID (score)

Note: The above video shows how to obtain the UI ID from the PC version only. For the mobile phone, Please see the below section.
 Finish, you can run the map. The leaderboard will work now.


(Optional) How to get UI Id on mobile phone

(Optional) Advance setting

  • - NUM_RANK_GET

Change this variable if you want to get more or less ranking data. The default is the top 10.

  • - LB_UPDATE_SEC

Change this variable if you want the leaderboard to update so often or slower (the default is to update every 12 seconds). But beware, don't update the leaderboard too often, the leaderboard may crash. You can see more details in this document. https://dev-wiki.mini1.cn/cyclopdeia?wikiMenuId=2125&wikiId=2208
Actually, I don't recommend anyone change this value.

(Optional) Display leaderboard sync time counter

  • Since our leaderboard will sync every N seconds, we should tell the player to know this. If not, the player may confuse why the leaderboard does not change. We suggest you add a number countdown to tell the player when the next update will occur.

(Optional) Future improvement

  • The cons of this basic leaderboard are cannot show data in real-time. Because we update the data from the server every N seconds (default is 12 seconds). And there is a delay time (0 seconds to 10 minutes) after requesting data until we receive the data back from the server.
  • This problem will not occur when we test our map in single-player mode. But it always occurs when run on the cloud server.
  • To overcome this delay update problem, many game developers will use 2 copies of the leaderboard technic.
    • The first one is the leaderboard data that get from the server.
    • The second one is the local copy data on the running machine.
  • We will do real-time updates of the data in the second copy and show it to the player. And we have to merge the copy from the server (the first copy) every time we get data back from the server.
  • By doing this technic, we can show the real-time data to the player. Suppose the player gets a +1 score, the leaderboard will immediately change.
  • But there is some issue that we have to concern if we use this technic. Because the data that the player sees in the leaderboard is not the real data on the server. We have to ensure that we can upload the real score of the player in time before the player exits the room. If not, the player may understand that his/her score already upload and exit the room.
  • This topic is far beyond the scope of this document. We may talk about it more in the future…

Code description

Function "callback2()"

  • This function will be called when the game receives the leaderboard data from the server. First, we will check if “v.nick” is nil or not. “v.nick” is the field that will keep the player's name and it will be valid when used on the cloud server only. When run in single-player mode, it will be nil. If “v.nick” is nil we will use the player name from “g_nameList” instead. For more details on the cloud server API and other APIs, please see this document. https://dev-wiki.mini1.cn/cyclopdeia?wikiMenuId=3&wikiId=2067

!!! And it is very important to know that after you call the cloud server API to get the data from the leaderboard, you will not immediately receive the callback. The callback may delay return up to several seconds or sometimes maybe a minute.

Function "Game_Run()"

  • This is the main function. What we do here is just increment the counter “gTick” until it reaches the time we want. And then we use the cloud server API to upload and download data from the server.

Function "mysplitlb()"

  • These are utility functions for test and debugging.

Function "Player_NewInputContentLB()"

  • These are utility functions for test and debugging.

Function "Game_PlayerEnterLB()"

  • Every time the player enters the map, we will keep their name in the table “g_nameList” for use in the above callback function.

developer_center/developer_editor/script/basic_rankings.txt · Last modified: 2024/05/16 18:05 by notsopro