一個 排序資料儲存器 本質上是一個 GlobalDataStore ,除了儲存值必須是 正整數 之外。它暴露了一個方法 GetSortedAsync() ,可以使用 DataStorePages 對象檢查排序的物件入進行檢查。
排序的數據儲存不支持版本和元數據,因此 DataStoreKeyInfo 永遠是 nil 對於 OrderedDataStore 中的鑰匙。如需版本控制和元數據協助,請使用 DataStore 。
排序的資料儲存不支持 userIds 或 SetAsync() 或 IncrementAsync() 的可選參數。
請參閱數據儲存以獲得使用訂閱數據儲存的概觀。
範例程式碼
This code sample demonstrates usage of an OrderedDataStore and pages.
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()
-- The data in 'topTen' is stored with the index being the index on the page
-- For each item, 'data.key' is the key in the OrderedDataStore and 'data.value' is the value
for rank, data in ipairs(topTen) do
local name = data.key
local points = data.value
print(name .. " is ranked #" .. rank .. " with " .. points .. "points")
end
-- Potentially load the next page...
--pages:AdvanceToNextPageAsync()
end
-- Create some data
pointsStore:SetAsync("Alex", 55)
pointsStore:SetAsync("Charley", 32)
pointsStore:SetAsync("Sydney", 68)
-- Display the top ten players
printTopTenPlayers()
概要
方法
- GetSortedAsync(ascending : boolean,pagesize : number,minValue : Variant,maxValue : Variant):DataStorePages
返回 DataStorePages 個對物件。
返回指定資料儲存中的鑰匙值和 DataStoreKeyInfo 個實個體、實例。
- IncrementAsync(key : string,delta : number,userIds : Array,options : DataStoreIncrementOptions):Variant
將鑰匙的值增加所提供的數量(兩者都必須是整數)。
移除指定的鑰匙,同時保留可存取的版本。
設置資料儲存的值為指定的鍵。
使用指定的回呼函數的新值來更新鑰鍵的值。
屬性
方法
GetSortedAsync
返回 DataStorePages 個對象。排序順序由 上升 決定,每頁長度由 頁面尺寸 決定,而 minValue / maxValue 是可選參數,用於過濾結果。
請參閱數據儲存以獲得請求限制和錯誤代碼說明。
參數
一個是否指示返回的數據頁是否排序上升的 boolean 值。
每頁的長度。預設值為 50。最大允許值為 100。
可選參數。如果設定,數值小於 minValue 的數據頁將被排除。
可選參數。如果設定,數值大於 maxValue 的數據頁將被排除。
返回
根據提供的參數排序的 DataStorePages 對象。