一个 订阅数据存储 实际上是一个 GlobalDataStore ,除了存储值必须是 正整数 。它暴露了一个方法 GetSortedAsync() ,可以使用 DataStorePages 对象检查排序的条目。
订阅数据存储不支持版本和元数据,因此 DataStoreKeyInfo 永远是 nil 对于 OrderedDataStore 中的键。如果需要版本控制和元数据协助,请使用 DataStore 。
排序数据存储不支持userIds或SetAsync()或IncrementAsync()的可选参数。
请参阅数据存储,了解有关使用订阅数据存储的概述。
代码示例
This code sample demonstrates usage of an OrderedDataStore and pages.
OrderedDataStore Basics
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 是可选参数,用于过滤结果。
请参阅数据存储以获取请求限制和错误代码的描述。
参数
一个 bool 指示返回的数据页是否按升序排列。
每页的长度。默认值为 50。最大允许值为 100。
minValue: Variant
可选参数。如果设置,数据页面的值小于 minValue 将被排除。
maxValue: Variant
可选参数。如果设置,数据页面的值大于 maxValue 将被排除。
返回
按提供的参数排序的 DataStorePages 对象。
属性继承自GlobalDataStore