學習
引擎資料類型
SharedTable

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡


範例程式碼
元素訪問
local st = SharedTable.new()
st[1] = "a"
st["x"] = true
st.y = 5
assert(st[1] == "a")
assert(st["x"] == true)
assert(st.x == true)
assert(st["y"] == 5)
assert(st.y == 5)
-- true 不是有效的 SharedTable 鍵,因此嘗試設置該鍵
-- 會失敗:
assert(not pcall(function() st[true] = 100 end))
-- 函數不是有效的 SharedTable 值,因此嘗試將值設置為
-- 函數會失敗:
assert(not pcall(function() st["f"] = function() end end))
元素迭代
local st = SharedTable.new({"a", "b", "c"})
for k, v in SharedTable.clone(st, false) do
print(k, ": ", v)
end
for k, v in st do
print(k, ": ", v)
end

API 參考
建構子
new
SharedTable.new()

new
SharedTable.new(t:table)
參數

函式
clear
SharedTable.clear(st:SharedTable):()
參數
返回
()

clone
SharedTable.clone(
參數
deep:boolean?
預設值:false

cloneAndFreeze
SharedTable.cloneAndFreeze(
參數
deep:boolean?
預設值:false

increment
SharedTable.increment(
st:SharedTable, key:string | number, delta:number
參數
delta:number
返回

isFrozen
SharedTable.isFrozen(st:SharedTable):boolean
參數
返回

size
SharedTable.size(st:SharedTable):number
參數
返回

update
SharedTable.update(
):()
返回
()

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。