主题
DataStoreOptions
DataStoreOptions 是获取 DataStore 或 OrderedDataStore 句柄时传入的实例级默认选项,后续读写方法未传入自己的 options 时会使用这些默认值。
概览
DataStoreOptions 是获取 DataStore 或 OrderedDataStore 句柄时传入的实例级默认选项,后续读写方法未传入自己的 options 时会使用这些默认值。
可通过
DataStoreOptions.New()构造
代码示例
创建带默认选项的 DataStore
lua
-- @runtime server
local DataStoreService = game:GetService('DataStoreService')
local Task = game:GetService('Task')
local options = DataStoreOptions.New()
options.AllScopes = true
options.WithKeyInfo = true
options.UseCache = false
local dataStore = DataStoreService:GetDataStore('PlayerData', nil, options)
Task:Spawn(function()
-- AllScopes=true 时,key 可以使用 scope/key 形式
local value, keyInfo = dataStore:GetAsync('global/player_001')
if keyInfo ~= nil then
print(keyInfo.Scope, keyInfo.Key, keyInfo.Version)
end
end)属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
AllScopes | Bool | false | 是否跨范围查询。 |
WithKeyInfo | Bool | false | 是否在返回结果中附带键信息(version, created/modified time, UserIds, Metas 等键元数据)。 |
KeepOldMetas | Bool | true | 更新时是否保留旧元数据。 |
ExcludeDeleted | Bool | false | 是否排除已删除的条目。 |
UseCache | Bool | false | 是否使用缓存。 |
PermanentlyRemove | Bool | false | 是否永久删除(而非软删除)。 |
UpdateTimeAsc | Bool | true | 是否按更新时间升序排列。 |
