Created
July 17, 2024 04:36
-
-
Save sonnguyen9800/1fe2281c81a312c22f4f139927264bc1 to your computer and use it in GitHub Desktop.
Roblox, Lua, Sample of Dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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