DataStorePages
Hiển Thị Bản Đã Lỗi Thời
*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.
Một loại đặc biệt của Pages đối tượng có các trang chứa cặp chìa khóa/giá trị từ một OrderedDataStore .Đối với đối tượng này, GetCurrentPage() trả về một mảng các bảng, mỗi chứa các chìa khóa có tên là key và value ; chúng phản ánh dữ liệu cặp chìa khóa/giá trị.
Mẫu mã
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()
Tóm Tắt
Phương Pháp
Phương Pháp kế thừa từ PagesTrả về các mục trên trang hiện tại. Các chìa khóa trong mục được xác định bởi nguồn của đối tượng này.
Lặp đến trang tiếp theo trong đối tượng trang, nếu có thể.
Thuộc Tính
Thuộc Tính được kế thừa từ Pages
Phương Pháp
Thuộc Tính được kế thừa từ Pages