Ok I got some where but I'm still getting an error..
Code:
local function scrollUpdate()
local list = db.events;
local line, lineplusoffset;
FauxScrollFrame_Update(frames.scroll,50,#list,20)
for line = 1, #list do
lineplusoffset = line + FauxScrollFrame_GetOffset(frames.scroll)
if lineplusoffset < 50 then
_G[MODNAME.."ScrollButton"..line]:SetText(list[lineplusoffset].set)
_G[MODNAME.."ScrollButton"..line]:Show()
else
_G[MODNAME.."ScrollButton"..line]:Hide()
end
end
end
function addon:CreateScrollFrame()
frames.scroll = CreateFrame("ScrollFrame", MODNAME.."ScrollFrame", UIParent, "FauxScrollFrameTemplate");
frames.scroll:SetWidth(118)
frames.scroll:SetHeight(180)
frames.scroll:SetPoint("CENTER", "UIParent", "CENTER", 0, 0)
frames.scroll:SetBackdrop({
bgFile="",
edgeFile="Interface\\Tooltips\\UI-Tooltip-Border",
tile="true",
tileSize= 32,
edgeSize=10,
insets = {left=5, right=5, top=5, bottom=5}
})
frames.scroll:SetBackdropBorderColor(0,.5,0,1)
frames.scroll:SetScript("OnVerticalScroll", function(self, offset) FauxScrollFrame_OnVerticalScroll(self, offset, 20, scrollUpdate) end)
frames.scroll:SetScript("OnShow", scrollUpdate);
for i = 1,#db.events do
local b
if i == 1 then
b = CreateFrame("Button", MODNAME.."ScrollButton"..i, frames.scroll)
b:SetPoint("TOPLEFT", 2,-5)
b:SetText("Button 1")
else
b = CreateFrame("Button", MODNAME.."ScrollButton"..i, _G[MODNAME.."ScrollButton"..(i-1)])
b:SetPoint("TOPLEFT", _G[MODNAME.."ScrollButton"..(i-1)], "BOTTOMLEFT", 0, 4)
b:SetText("Button "..i)
end
b:SetNormalFontObject("GameFontNormalSmall")
b:RegisterForClicks("LeftButtonUp")
b:SetWidth(114)
b:SetHeight(20)
b:SetBackdrop({
bgFile = "Interface\\CHATFRAME\\CHATFRAMEBACKGROUND",
edgeFile = "",
tile = "true",
tileSize = 32,
edgeSize = 10,
insets = {left = 3, right = 3, top = 3, bottom = 3}
})
b:SetBackdropColor(1,1,1,1)
b:SetScript("OnClick",
function()
self:Print("Button Onclick!");
end
)
end
end
The error I'm getting is:
core.lua:242: attempt to index field '?' (a nil value)
Line 242 is _G[MODNAME.."ScrollButton"..line]:SetText(list[lineplusoffset].set)
Which probably means that its trying to get data from an index in an array that doesn't exist. And this only occurs when I'm scrolling the verticale scroll bar.
My Data set looks like this:
Code:
["events"] = {
{
["set"] = "DPS",
["event"] = "PVP",
["talent"] = "Primary",
}, -- [1]
{
["set"] = "Lance",
["event"] = "Mounted",
["talent"] = "Primary",
}, -- [2]
{
["set"] = "Tank",
["event"] = "City",
["talent"] = "Primary",
}, -- [3]
{
["event"] = "Evocation",
["set"] = "DPS",
}, -- [4]
},
I"m trying to output the data in each index of the "events" array to a line item/button in the scroller.