Skip to content

Instantly share code, notes, and snippets.

@sonnguyen9800
Created July 17, 2024 04:36
Show Gist options
  • Save sonnguyen9800/1fe2281c81a312c22f4f139927264bc1 to your computer and use it in GitHub Desktop.
Save sonnguyen9800/1fe2281c81a312c22f4f139927264bc1 to your computer and use it in GitHub Desktop.
Roblox, Lua, Sample of Dictionary
local SoulType = require(game.ReplicatedStorage.Shared.define.play).SpiritType
local UIConfigGlobal = {
}
UIConfigGlobal.StatsPanel = {
[SoulType.Red] = {
Name = "Hyper Star",
Color = Color3.fromRGB(255, 0, 127),
},
[SoulType.Yellow] = {
Name = "Stamina Star",
Color = Color3.fromRGB(255, 170, 0),
},
[SoulType.Green] = {
Name = "Swift Soul",
Color = Color3.fromRGB(85, 170, 0),
},
}
-- Create a metatable for the dictionary
local dictionaryMetaTable = {
__index = UIConfigGlobal,
__newindex = function(table, key, value)
error("Attempt to modify a const table", 2)
end
}
-- Wrap the UIConfigGlobal with the metatable
setmetatable(UIConfigGlobal, dictionaryMetaTable)
return UIConfigGlobal
-- Accesing StatsPanel by `myDict.StatsPanel`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment