DataStoreService
非推奨を表示
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
DataStoreService は、GlobalDataStore および OrderedDataStore オブジェクトを取得するためのメソッドを露出します。データストアはゲームサーバーにのみアクセスできるため、DataStoreService 内でのみ、Script または ModuleScript が使用されている Script 内でのみ使用できます。
データストアについて詳しくは、データストアを参照してください。データ構造、管理、エラー処理などの詳細ガイド。
コードサンプル
This code sample prints the request budget for all data store request types.
DataStore Budget
local DataStoreService = game:GetService("DataStoreService")
for _, enumItem in pairs(Enum.DataStoreRequestType:GetEnumItems()) do
print(enumItem.Name, DataStoreService:GetRequestBudgetForRequestType(enumItem))
end
概要
プロパティ
データストア機能が自動的に再試行するかどうかを設定します。データストアサービスは、技術的な理由により自動再試行が無効になったため、このプロパティを尊重しません。そのため、操作を再試行するシステムを自分で実装する必要があります。
方法
提供された名前とスコープで DataStore インスタンスを作成します。
デフォルトのデータストアを返す。
名とオプションのスコープが与えられた OrderedDataStore を取得する
指定されたリクエストタイプで行えるリクエスト数を返します。
すべてのエクスペリエンスのデータストアを列挙するための DataStoreListingPages オブジェクトを返します。
プロパティ
AutomaticRetry
方法
GetDataStore
パラメータ
戻り値
GetGlobalDataStore
戻り値
コードサンプル
GlobalDataStore インスタンスを取得する
local DataStoreService = game:GetService("DataStoreService")
local GlobalDataStore = DataStoreService:GetGlobalDataStore()
print(GlobalDataStore.Name)
GetOrderedDataStore
パラメータ
戻り値
コードサンプル
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()
GetRequestBudgetForRequestType
パラメータ
既定値: ""
戻り値
コードサンプル
Print Request Budget
local DataStoreService = game:GetService("DataStoreService")
local globalStore = DataStoreService:GetGlobalDataStore()
local function printBudget()
local budget = DataStoreService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync)
print("Current set/increment budget:", budget)
end
for i = 1, 5 do
local key = "key" .. i
local success, err = pcall(function()
globalStore:SetAsync(key, true)
end)
if success then
printBudget()
else
print(err)
end
end