I was creating my program, making clickable buttons. They worked perfectly as expected. It was done by creating a table called "button" and implementing in it some functions to handle buttons. Buttons are created and saved in the same table ("button") called "buttons":
local button = {
buttons = {},
add = function (self, and other variables)
--blah, blah
end,
remove = function (same stuff)
--another function
end,
--More functions...
}
Now, I didn't want all of my buttons to be in button.buttons table, so I wrote this:local butt1 = setmetatable({}, {__index = button})
local butt2 = setmetatable({}, {__index = button})
butt1:add("blah, blah", arguments...)
butt1:draw()
This worked as expected, so I wanted to check what will the code do if there is no buttons in the "buttons" table, so I tried to draw buttons from the "butt2" table:
butt2:draw()And it did draw a button, the one that I created in the "butt1" table. So I was searching how to fix it and I found it. I deleted the "buttons" table from "button" table:
local button = {
--removed the "buttons = {}," line
add = function (self, and other variables)
--blah, blah
end,
remove = function (same stuff)
--another function
end,
--More functions...
}
and defined that table in the setmetatable method:local butt1 = setmetatable({buttons = {}}, {__index = button})
local butt2 = setmetatable({buttons = {}}, {__index = button})
and then "butt2:draw()" didn't draw any buttons (as it should be).So, my question is that:
Why is it behaving like that? Maybe "setmetatable()" method is making table "buttons" public to every other instance (wrong word, don't remember other words) of "button" table?
Here are the codes (just run it in CC, they don't error):
Working:
Spoiler
Not Working:
Spoiler












