เรียนรู้
Engine Class
MemoryStoreSortedMap
ไม่สามารถสร้าง
ไม่ซ้ำ

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่


สรุป
วิธีการ
GetRangeAsync(direction: Enum.SortDirection,count: number,exclusiveLowerBound: Variant,exclusiveUpperBound: Variant):{any}
SetAsync(key: string,value: Variant,expiration: number,sortKey: Variant):boolean
UpdateAsync(key: string,transformFunction: function,expiration: number):Tuple
สมาชิกที่ได้รับทอด

เอกสารอ้างอิงเกี่ยวกับ API
วิธีการ
GetAsync
ผลตอบแทน
ความสามารถ: DataStore
MemoryStoreSortedMap:GetAsync(key:string):Tuple
พารามิเตอร์
key:string
ส่งค่ากลับ

GetRangeAsync
ผลตอบแทน
ความสามารถ: DataStore
MemoryStoreSortedMap:GetRangeAsync(
direction:Enum.SortDirection, count:number, exclusiveLowerBound:Variant, exclusiveUpperBound:Variant
พารามิเตอร์
count:number
exclusiveLowerBound:Variant
exclusiveUpperBound:Variant
ส่งค่ากลับ
ตัวอย่างโค้ด
การดึงคีย์ MemoryStore
local MemoryStoreService = game:GetService("MemoryStoreService")
local myMap = MemoryStoreService:GetSortedMap("MySortedMap")
function printAllKeys(map)
-- ขอบล่างเริ่มต้นคือ nil ซึ่งหมายถึงเริ่มจากรายการแรกสุด
local exclusiveLowerBound = nil
-- ลูปนี้จะดำเนินต่อไปจนกว่าจะถึงจุดสิ้นสุดของแผนที่
while true do
-- รับรายการได้สูงสุดถึงร้อยรายการเริ่มจากขอบล่างปัจจุบัน
local items = map:GetRangeAsync(Enum.SortDirection.Ascending, 100, exclusiveLowerBound)
for _, item in ipairs(items) do
print(item.key)
print(item.sortKey)
end
-- หากการเรียกคืนรายการน้อยกว่าร้อยรายการ หมายความว่าเราได้ถึงจุดสิ้นสุดของแผนที่
if #items < 100 then
break
end
-- คีย์สุดท้ายที่เรียกคืนคือขอบล่างพิเศษสำหรับการทำซ้ำในครั้งถัดไป
exclusiveLowerBound = {}
exclusiveLowerBound["key"] = items[#items].key
exclusiveLowerBound["sortKey"] = items[#items].sortKey
end
end
printAllKeys(myMap)

GetSizeAsync
ผลตอบแทน
ความสามารถ: DataStore
MemoryStoreSortedMap:GetSizeAsync():number
ส่งค่ากลับ

RemoveAsync
ผลตอบแทน
ความสามารถ: DataStore
MemoryStoreSortedMap:RemoveAsync(key:string):()
พารามิเตอร์
key:string
ส่งค่ากลับ
()

SetAsync
ผลตอบแทน
ความสามารถ: DataStore
MemoryStoreSortedMap:SetAsync(
key:string, value:Variant, expiration:number, sortKey:Variant
พารามิเตอร์
key:string
value:Variant
expiration:number
sortKey:Variant
ส่งค่ากลับ

UpdateAsync
ผลตอบแทน
ความสามารถ: DataStore
MemoryStoreSortedMap:UpdateAsync(
key:string, transformFunction:function, expiration:number
พารามิเตอร์
key:string
transformFunction:function
expiration:number
ส่งค่ากลับ
ตัวอย่างโค้ด
การอัปเดตแผนที่ที่จัดเรียงใน MemoryStore
local MemoryStoreService = game:GetService("MemoryStoreService")
local map = MemoryStoreService:GetSortedMap("Leaderboard")
local Players = game:GetService("Players")
function updateLeaderboard(itemKey, killsToAdd, deathsToAdd)
local success, newStats, newScore = pcall(function()
return map:UpdateAsync(itemKey, function(playerStats, playerScore)
playerStats = playerStats or { kills = 0, deaths = 0 }
playerStats.kills += killsToAdd
playerStats.deaths += deathsToAdd
if playerStats then
-- `playerScore` คือ sortKey ที่ใช้ในการจัดเรียงรายการในแผนที่
playerScore = playerStats.kills / math.max(playerStats.deaths, 1)
return playerStats, playerScore
end
return nil
end, 30)
end)
end
-- เพิ่มการฆ่า 1 ครั้งให้กับผู้เล่นทั้งหมด
for i, player in pairs(Players:GetPlayers()) do
updateLeaderboard(player.UserId, 1, 0)
end
-- เพิ่มการฆ่า 5 ครั้งและการตาย 1 ครั้งให้กับผู้เล่นที่มี userId 12345
updateLeaderboard(12345, 5, 1)

©2026 Roblox Corporation. Roblox, โลโก้ Roblox และ Powering Imagination เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ