Originally Posted by Coldkil
Another thing that came out of my mind: if i want to be actually able to manage the bars, i need to provide some way to refer to those elements outside of the function code, right?
So, the idea was this (pseudocode again):
Code:
function createSplitBar (containerframe, [rest of arguments])
local splittable ={}
for i = 1, # do
-- create bars code here
splittable[i] = bar
end
containerframe.splittable = splittable
end
-- now i should be able to call it this way
playerframe.splittable[2]:SetStatusBarColor(.3,.4,.5)
-- or whatever other operation i want to do on bars
Is there something wrong (again, logic wise, code is just thrown there)?
|
Nah, everything is fine, I'd also create a method that allowed me to update all bars in that table at once and add it to
containerframe:
Lua Code:
local function updateBars(self, method, ...)
for _, bar in next, self.splittable do
if bar[method] then
bar[method](bar, ...)
end
end
end
local function createSplitBar(containerFrame, ...)
-- stuff here
containerFrame.UpdateBars = updateBars
end
-- containerFrame:UpdateBars("SetStatusBarColor", 0.3, 0.4, 0.5)
-- instead of
-- containerFrame.splittable[1]:SetStatusBarColor(0.3, 0.4, 0.5)
-- containerFrame.splittable[2]:SetStatusBarColor(0.3, 0.4, 0.5)
-- containerFrame.splittable[3]:SetStatusBarColor(0.3, 0.4, 0.5)
-- ...