概要
方法
GetSortedAsync(ascending: boolean,pagesize: number,minValue: Variant,maxValue: Variant):DataStorePages |
範例程式碼
有序數據存儲基礎
local DataStoreService = game:GetService("DataStoreService")
local pointsStore = DataStoreService:GetOrderedDataStore("Points")
local function printTopTenPlayers()
local isAscending = false
local pageSize = 10
local pages = pointsStore:GetSortedAsync(isAscending, pageSize)
local topTen = pages:GetCurrentPage()
-- 'topTen' 中的數據 是以索引為頁面上的索引進行存儲
-- 對於每個項目,'data.key' 是有序數據存儲中的鍵,而 'data.value' 是值
for rank, data in ipairs(topTen) do
local name = data.key
local points = data.value
print(name .. " 的排名是 #" .. rank .. ",得分是 " .. points .. " 分")
end
-- 可能加載下一頁...
--pages:AdvanceToNextPageAsync()
end
-- 創建一些數據
pointsStore:SetAsync("Alex", 55)
pointsStore:SetAsync("Charley", 32)
pointsStore:SetAsync("Sydney", 68)
-- 顯示前十名 玩家
printTopTenPlayers()API 參考
方法
GetSortedAsync
OrderedDataStore:GetSortedAsync(