View Single Post
07-08-13, 01:52 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
You have global leaks at the following lines. A global leak is when a variable that is meant to be local is not defined as such and its value "leaks" into the global environment. Note you only need to define a variable as a local once. From then on, Lua will recognize it as a local variable.
Code:
--scrollframe 
local scrollframe = CreateFrame("ScrollFrame", nil, frame)
Code:
--scrollbar 
local scrollbar = CreateFrame("Slider", nil, scrollframe, "UIPanelScrollBarTemplate")




Code:
local button = CreateFrame("Button", "ButtonName", Parentframe,"UIPanelButtonTemplate")
ButtonName:SetText("My Name is Button")
ButtonName:SetPoint("point", "releventframe", "relativePoint", offsetx,offsety)
ButtonName:SetWidth(110)
ButtonName:SetHeight(50)
The template you used for the buttons at the bottom of your code is one of the worst ways to do this. You're assigning the frame returned by CreateFrame() to a local and never using it. It would be better to use the local instead of referencing the global environment by the frame's name.

This is also where the problem with the frame's name being generic is as pointed out by Seerah. When 2 frames with the same name are created by CreateFrame(), it creates and returns each frame individually as expected, but only the first frame will be stored in the global environment. When using this method of setting up your button, you will not only lose access to the button you had created, but also corrupt whatever frame was stored in said global. In some cases, if the stored frame is of a different frame type than what you had created, you may run into Attempt to call nil errors when using type-specific functions.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 07-08-13 at 01:54 PM.
  Reply With Quote