OrderedDataStore
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
A ร้านข้อมูลสั่งซื้อ เป็นหลักเป็นเพียง GlobalDataStore ยกเว้นว่ามูลค่าที่เก็บไว้จะต้องเป็นตัวเลขบวก **** มันเปิดเผยวิธี GetSortedAsync() ซึ่งสามารถตรวจสอบเอนทรีในลำดับที่เรียงลําดับโดยใช้วัตถุ DataStorePages
ร้านข้อมูลที่สั่งซื้อไม่สนับสนุนการจัดเวอร์ชันและเมทาดาต้า ดังนั้น DataStoreKeyInfo จึงเป็นเสมอ nil สำหรับกุญแจใน OrderedDataStoreหากต้องการการสนับสนุนเวอร์ชันและข้อมูลคำอธิบาย, ให้ใช้ DataStore
ร้านข้อมูลที่สั่งซื้อไม่สนับสนุนพารามิเตอร์ทางเลือก userIds สำหรับ SetAsync() หรือ IncrementAsync()
ดู ร้านข้อมูล สำหรับภาพรวมเกี่ยวกับการใช้ร้านข้อมูลที่สั่งซื้อ
ตัวอย่างโค้ด
This code sample demonstrates usage of an OrderedDataStore and pages.
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()
สรุป
วิธีการ
- GetSortedAsync(ascending : boolean,pagesize : number,minValue : Variant,maxValue : Variant):DataStorePages
ส่งคืนวัตถุ DataStorePages
ส่งค่าของกุญแจในคลังข้อมูลที่กำหนดและตัวอย่าง DataStoreKeyInfo อินสแตนซ์
- IncrementAsync(key : string,delta : number,userIds : Array,options : DataStoreIncrementOptions):Variant
เพิ่มมูลค่าของกุญแจโดยจำนวนที่กำหนด (ทั้งสองต้องเป็นตัวเลข)
ลบคีย์ที่ระบุโดยยังคงรักษารุ่นที่เข้าถึงได้
ตั้งค่าค่าของคลังข้อมูลสำหรับกุญแจที่กำหนดไว้
อัปเดตค่าของกุญแจด้วยค่าใหม่จากฟังก์ชันการโทรกลับที่กำหนดไว้
คุณสมบัติ
วิธีการ
GetSortedAsync
ส่งคืนวัตถุ DataStorePagesลำดับการจัดเรียงจะถูกกำหนดโดย เพิ่มขึ้น , ความยาวของแต่ละหน้าโดย pageSize และ minValue / maxValue เป็นพารามิเตอร์ที่เลือกได้ซึ่งจะกรองผลลัพธ์
ดู ร้านข้อมูล สำหรับขีดจํากัดคำขอและคําอธิบายของรหัสข้อผิดพลาด
พารามิเตอร์
เป็นไบนารีที่ระบุว่าหน้าข้อมูลที่ส่งคืนอยู่ในลำดับเพิ่มขึ้นหรือไม่
ความยาวของแต่ละหน้า โดยค่าเริ่มต้นคือ 50 ค่าสูงสุดที่อนุญาตคือ 100
พารามิเตอร์ทางเลือก หากตั้งค่าแล้ว หน้าข้อมูลที่มีค่าน้อยกว่า minValue จะถูกยกเลิก
พารามิเตอร์ทางเลือก หากตั้งค่าแล้ว หน้าข้อมูลที่มีค่ามากกว่า maxValue จะถูกยกเลิก
ส่งค่ากลับ
วัตถุจัดเรียง DataStorePages ที่อ้างอิงตามอาร์กิวเมนต์ที่ให้ไว้