Originally Posted by ChaosInc
As far as the checkbuttons, it's only creating one and stopping (leading to the error, figured that part out). I'm looking for WHY it's not building all the buttons.
|
Code:
cb:SetScript("OnClick", setLoc(i))
Was that line meant to be:
Code:
cb:SetScript("OnClick", function() setLoc(i) end)
As it is now you are trying to set the "OnClick" script for each button to the return value of setLoc, but in calling setLoc you are attempting to reference frames that haven't been created yet.
Edit:
Instead of creating a separate function for each frame's "OnClick" handler why not just do:
Code:
local function setLoc(self)
for i = 1, #cityList do
_G["MageTaxi_City" .. i]:SetChecked(false)
end
dest = cityList[self.id]
self:SetChecked(true)
end
function MageTaxi_createGUI()
-- other code
for i = 1, #cityList do
cb = CreateFrame("CHECKBUTTON", "MageTaxi_City" .. i, f, "UIRadioButtonTemplate")
if i == 1 then
cb:SetPoint("TOPLEFT", f, "TOPLEFT", 40, -45)
else
cb:SetPoint("TOP", "MageTaxi_City" .. (i - 1), "BOTTOM", 0, -10)
end
cb.id = i
cb:SetScript("OnClick", setLoc) -- line 149
end
end