Klasa silnika
DataStore
*Ta zawartość została przetłumaczona przy użyciu narzędzi AI (w wersji beta) i może zawierać błędy. Aby wyświetlić tę stronę w języku angielskim, kliknij tutaj.
Podsumowanie
Metody
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):() |
Członkowie odziedziczeni
6 odziedziczonych od: GlobalDataStore
57 odziedziczonych od: Instance
6 odziedziczonych od: Object
Materiały referencyjne dotyczące interfejsów API
Metody
GetVersionAsync
GetVersionAtTimeAsync
Zwroty
Przykłady kodu
Pobieranie wersji DataStore według czasu
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("Nie znaleziono wersji o tej porze")
else
print(result, keyInfo.Version)
end
else
warn(result)
end
end
-- Wcześniej uruchomiono o 2024/12/02 6:00 UTC
setData("wersja 1")
-- Wcześniej uruchomiono o 2024/12/02 9:00 UTC
setData("wersja 2")
-- Wyświetla "Nie znaleziono wersji o tej porze"
local time1 = DateTime.fromUniversalTime(2024, 12, 02, 05, 00)
getVersionAtTime(time1)
-- Wyświetla "wersja 1 <version>"
local time2 = DateTime.fromUniversalTime(2024, 12, 02, 07, 00)
getVersionAtTime(time2)
-- Wyświetla "wersja 2 <version>"
local time3 = DateTime.fromUniversalTime(2024, 12, 02, 10, 00)
getVersionAtTime(time3)ListKeysAsync
DataStore:ListKeysAsync(
Zwroty
ListVersionsAsync
DataStore:ListVersionsAsync(
Parametry
| Wartość domyślna: "Ascending" |
| Wartość domyślna: 0 |
| Wartość domyślna: 0 |
| Wartość domyślna: 0 |
Zwroty
Przykłady kodu
Pobieranie wersji DataStore z filtrem daty
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("Klucz:", key, "; Wersja:", info.Version, "; Utworzono:", info.CreatedTime, "; Usunięto:", info.IsDeleted)
end
endRemoveVersionAsync