Quantcast
WoWInterface - View Single Post - adding a GUI for addon options
View Single Post
06-01-10, 01:29 PM   #12
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,510
Well, your two pieces of code are fine as they are but apart from setting your variable in one and printing it in another you are not showing how they work together.

For example, you have that print statement to see if your variable is set. When is that set to run ? In the main chunk of the code, in a function called when an event is triggered, in a function called from another function etc.

Also, when is BadBoy CheckBox code set up ? Is it after you have initialised and loaded the saved variables ?

Using the code you supplied it should work in the following order if in the same lua file :

Code:
alUI_DB = {}
alUI_DB.example = true


local frame = CreateFrame("CheckButton", "alUIConfigButton1", al)
frame:SetWidth(26)
frame:SetHeight(26)
frame:SetPoint("TOPLEFT", 16, -52)
frame:SetScript("OnShow", function(frame)
	if alUI_DB.example then
		frame:SetChecked(true)
	else
		frame:SetChecked(false)
	end
end)
frame:SetScript("OnClick", function(frame)
	local tick = frame:GetChecked()
	if tick then
		PlaySound("igMainMenuOptionCheckBoxOn")
		alUI_DB.example = true
	else
		PlaySound("igMainMenuOptionCheckBoxOff")
		alUI_DB.example = false
	end

             -- Now react to the changes
             if ( alUI_DB.example ) then
                print("Yay");
             else
                print("Off")
             end
end)


-- Slight change here
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(_, _, name)
	if name ~= "alUI" then return end

             -- use existing/loaded table or create a new one
             alUI_DB = alUI_DB or {}

             -- use existing/loaded variable or set default
             alUI_DB.example = alUI_DB.example or true

             f:UnregisterEvent("ADDON_LOADED")
	f:SetScript("OnEvent", nil)

             -- React to the loaded value
             if ( alUI_DB.example ) then
                print("Yay");
             else
                print("Off")
             end
end)
__________________
  Reply With Quote