September 20, 2022


Only the server can access

This class must passGetrankdatastore of DataService classMethod acquisition

Because the database needs to be operated, the operations of setting and obtaining data are performed asynchronously and will not take effect immediately. When the network conditions are poor, it may take longer to wait. The data in the editor environment will only exist locally, so it is not necessary to There are the above problems

Brief Introduction

Leaderboard data storage can be used to make leaderboards. You can also use global data storage to store leaderboard data. However, leaderboard data storage is an API specifically for leaderboard functions, so it is more convenient to use leaderboard data storage to make leaderboards.


void SetDatastring key, int value )
Set the value on the corresponding key. The value type must be an integer
void RemoveDatastring key )
Remove the value on the corresponding key
void RequestDatastring key, function callback )
Get the value on the corresponding key
void RequestRangeDataint beginIndex, int endIndex, function callback )
Get the data of the specified ranking range, and sort the data from large to small according to the value of the data
void UpdateDatastring key, function callback )
Update the value on the corresponding key
void IncreaseDatastring key, int delta )
Increase the value on the corresponding key
void SetExpireTimeint expireTimeStamp )
Set the timestamp when the ranking data expires

Code example

Use the leaderboard data storage to create a "player combat power" leaderboard.

--Get leaderboard data in the "player combat power" space
local playerPowerData = Engine.DataService:GetRankDataStore("PlayerPower")

-- Set data
playerPowerData:SetData("PlayerA", 10)
playerPowerData:SetData("PlayerB", 50)
playerPowerData:SetData("PlayerC", 42)
playerPowerData:SetData("PlayerD", 16)

-- Get the top 5 data
playerPowerData:RequestRangeData(1, 5, function(powerDataList)
    for index, data in ipairs(powerDataList) do
        print(index, data.key, data.value)