Is it possible to convert a key in object? I would like to simplify this code:
This works:
for key, data in pairs(DBButtonOptions[self.value]) do
if key == "widgetframe1" then
widgetframe1:SetText(data)
widgetframe1:SetDisabled(enable)
elseif key == "widgetframe2" then
widgetframe2:SetText(data)
widgetframe2:SetDisabled(enable)
elseif key == "widgetframe3" then
widgetframe3:SetText(data)
widgetframe3:SetDisabled(enable)
elseif key == "widgetframe4" then
widgetframe4:SetText(data)
widgetframe4:SetDisabled(enable)
elseif key == "widgetframe5" then
widgetframe5:SetText(data)
widgetframe5:SetDisabled(enable)
end
end
This does not work:
for key, data in pairs(DBButtonOptions[self.value]) do
key:SetText(data)
key:SetDisabled(enable)
end
This works but error (Attempt to index local key):
for key, data in pairs(DBButtonOptions[self.value]) do
local key = _G[key]
key:SetText(data)
key:SetDisabled(enable)
end
local control = _G[key]? Also what do you mean by it works but you get an error? Is it possible there is a key that isn't a control with SetText and SetDisabled functions?