Lớp công cụ
DataStore
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm Tắt
Phương Pháp
GetVersionAsync(key: string,version: string):Tuple |
GetVersionAtTimeAsync(key: string,timestamp: number):Tuple |
ListKeysAsync(prefix: string,pageSize: number,cursor: string,excludeDeleted: boolean):DataStoreKeyPages |
ListVersionsAsync(key: string,sortDirection: Enum.SortDirection,minDate: number,maxDate: number,pageSize: number):DataStoreVersionPages |
RemoveVersionAsync(key: string,version: string):() |
Thành viên kế thừa
6 thành viên kế thừa từ GlobalDataStore
57 thành viên kế thừa từ Instance
6 thành viên kế thừa từ Object
Tài Liệu Tham Khảo API
Phương Pháp
GetVersionAsync
GetVersionAtTimeAsync
Lợi Nhuận
Mẫu mã
Lấy phiên bản DataStore theo thời gian
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("DataStore")
local key = "key-123"
function setData(data)
local success, result = pcall(function()
dataStore:SetAsync(key, data)
end)
if not success then
warn(result)
end
end
function getVersionAtTime(timestamp)
local success, result, keyInfo = pcall(function()
return dataStore:GetVersionAtTimeAsync(key, timestamp.UnixTimestampMillis)
end)
if success then
if result == nil then
print("Không tìm thấy phiên bản nào tại thời gian")
else
print(result, keyInfo.Version)
end
else
warn(result)
end
end
-- Đã chạy trước đó vào 2024/12/02 6:00 UTC
setData("phiên bản 1")
-- Đã chạy trước đó vào 2024/12/02 9:00 UTC
setData("phiên bản 2")
-- In "Không tìm thấy phiên bản nào tại thời gian"
local time1 = DateTime.fromUniversalTime(2024, 12, 02, 05, 00)
getVersionAtTime(time1)
-- In "phiên bản 1 <phiên bản>"
local time2 = DateTime.fromUniversalTime(2024, 12, 02, 07, 00)
getVersionAtTime(time2)
-- In "phiên bản 2 <phiên bản>"
local time3 = DateTime.fromUniversalTime(2024, 12, 02, 10, 00)
getVersionAtTime(time3)ListKeysAsync
DataStore:ListKeysAsync(
Lợi Nhuận
ListVersionsAsync
DataStore:ListVersionsAsync(
Tham Số
| Giá Trị Mặc Định: "Ascending" |
| Giá Trị Mặc Định: 0 |
| Giá Trị Mặc Định: 0 |
| Giá Trị Mặc Định: 0 |
Lợi Nhuận
Mẫu mã
Lấy các phiên bản DataStore với bộ lọc ngày
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
local time = DateTime.fromUniversalTime(2020, 10, 09, 01, 42)
local listSuccess, pages = pcall(function()
return experienceStore:ListVersionsAsync("User_1234", nil, time.UnixTimestampMillis)
end)
if listSuccess then
local items = pages:GetCurrentPage()
for key, info in pairs(items) do
print("Khóa:", key, "; Phiên bản:", info.Version, "; Ngày tạo:", info.CreatedTime, "; Đã xóa:", info.IsDeleted)
end
endRemoveVersionAsync