I have this proxy table:
local Proxy = setmetatable({result = {"AdorneeId", "Adornee", "Name", "Exp", "BaseStats", "IndividualValues", "EffortValues" , "Type1", "Type2", "Stats", "Image", "Health", "Energy", "StatusEffect", "Effects", "StatModifiers", "MovePool", "Moves"}} , {
__tostring = function()
return NewCreature.Name -- the name
end,
__index = function(proxy, key)
local result = rawget(proxy,"result")
if result[key] ~= nil then
print(string.format("%q was accessed", key))
else
error(string.format("%s is not a valid member of %s %q", key, tostring(proxy), tostring(proxy)))
end
if key == "Health" or key == "Energy" then
end
return NewCreature[key]
end,
__newindex = function(proxy, key, value)
local result = rawget(proxy,"result")
if result[key] ~= nil then -- shows what action is being done
if value == nil then
print(string.format("%q was deleted", key))
elseif result[key] ~= value then
print(string.format("%q was changed", key))
end
else
print(string.format("%q was set", key))
end
NewCreature[key] = value -- set the value
end
})
And i am starting to realise that it may not work well with nested tables.
i.e: Index “Stats” returns a dictionary with stats, so if i were to type ProxyTable.Stats.Attack, my question is if this would trigger the metamethod twice or only once for “Stats”