I'm basically creating my custom GuiLibrary, that has its own Gui elements(they still use roblox original gui elements, im just creating wrapper around them with more functionalty) and they have their own methods and functions and different properties, just like roblox Gui elements have.
In the Module Script code i have "obj.Size" table with parameters, i can detect change in obj table through __newindex, but how would i go about detecting change inside obj.Size table? If i change for example: obj.Size.x i want to fire the bindableEvent i have inside my obj table. So that's basically the problem is, i can detect variable change inside obj table, but not in obj.Size table, how would i go about this?
Module Script code:
local module = {}
function module.new(o)
local obj = {}
obj.Changed = Instance.new('BindableEvent')
obj.Name = 'ScrollableFrameName'
obj.Size = {x = 50,y = 100}
obj.mt = {}
obj.mt.__index = function(tbl,key)
return obj[key]
end
obj.mt.__newindex = function(tbl,property,value)
--print('Property'..property..' changed to: '..value)
obj[property] = value
obj.Changed:Fire(property,value)
end
local proxy = setmetatable(o or {},obj.mt)
return proxy
end
return module
Regular Script code:
local ScrollableFrameModule = require(script.Parent:WaitForChild('ScrollableFrame'))
local ScrollableFrame = ScrollableFrameModule.new()
ScrollableFrame.Changed.Event:connect(function(property,value)
print('Changed property:'..property..' to '..value)
end)
ScrollableFrame.Size.x = 999
ScrollableFrame.Name = '123'

1 comment
You have to do the same
__newindextrick you did for theScrollableFramefor theSizeTable.