View Single Post
02-13-18, 08:41 AM   #20
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Originally Posted by Coldkil View Post
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:
  1. local function updateBars(self, method, ...)
  2.     for _, bar in next, self.splittable do
  3.         if bar[method] then
  4.             bar[method](bar, ...)
  5.         end
  6.     end
  7. end
  8.  
  9. local function createSplitBar(containerFrame, ...)
  10.     -- stuff here
  11.     containerFrame.UpdateBars = updateBars
  12. end
  13.  
  14. -- containerFrame:UpdateBars("SetStatusBarColor", 0.3, 0.4, 0.5)
  15. -- instead of
  16. -- containerFrame.splittable[1]:SetStatusBarColor(0.3, 0.4, 0.5)
  17. -- containerFrame.splittable[2]:SetStatusBarColor(0.3, 0.4, 0.5)
  18. -- containerFrame.splittable[3]:SetStatusBarColor(0.3, 0.4, 0.5)
  19. -- ...
__________________
  Reply With Quote