I learned metatables rcenetly and I’m trying to implement it in my recent game, I’m making a fighting game with different fighting stances/styles.
I made a module that returns a table with all the styles and all of their animation, but I want to set default animations so if the style doesnt have a unique block animation it uses the default one but since I’m using a dictionary I’m not sure how I can do such thing with metatables.
local module = {}
local default_animations = {
["Block"] = "123123213",
}
module.Styles = {
["Street Fighting"] = {
["1"] = "1231232",
["2"] = "123123",
["Skills"] = {}
}
}
for i,v in pairs(module.Styles) do
print(v)
if typeof(v) == "table" then
setmetatable(v, default_animations)
v.__index = default_animations
end
end
return module
Server Script Test:
local module = require(game.ReplicatedStorage.Styles)
print(module.Styles["Street Fighting"].Block)