When I script, I like to know why what I do works and I’ve run into that issue where I don’t know what I’m doing and I don’t know why this works.
I recently had an issue where I couldn’t find out how to get arguments through __index but I was able to find a solution for that, but I don’t understand why it works.
local meta = {
__index = function(tbl, key)
if type(currentDummy[key]) == 'function' then
return function(tbl, ...) -- here, I don't get why I have to return a new function whose first arguments are tbl and then I have to do the vararg if that makes sense
return currentDummy[key](currentDummy,...) -- I don't understand how the ... gets assigned a value
end
else
return currentDummy[key]
end
end;
__newindex = function(tbl, key, value)
if currentDummy[key] ~= nil then
currentDummy[key] = value
end
end;
}
return setmetatable(funcs, meta)
Basically, when I do :WaitForChild() on the metatable, it works as intended, why?
So line two in the second script shows currentDummy being created via clone of dummy I believe I need to see what dummy is.
For me to understand what the construct of the table is I need to see its construction.
You may feel I am wasting your time but if you need my help then please supply more details.
local WaitForChild = instance.WaitForChild -- here, WaitForChild is a function
WaitForChild(instance, "someChild") -- here, you call the function
You are still indexing the table.
return function(tbl, ...)
return currentDummy[key](currentDummy,...)
end
It appears like it’s a proxy table. tbl would be the table itself. Since you want it to be the instance, you have to replace the first argument with the dummy instance, to call WaitForChild on it.