Thread Tools Display Modes
08-20-15, 07:03 PM   #1
Endzeit
A Deviate Faerie Dragon
Join Date: Aug 2015
Posts: 12
Disable Button: if variable == false



i searched in the api for hours now.. i found only button:disabled().. but it is the wrong code i think.
My Buttons left Work, but i want to disable the Button, when "Raidbuffs anzeigen" is unchecked. Like the Right Side of Picture.

Lua Code:
  1. local e_raidbuffs = CreateFrame("CheckButton", "EndzeitUIConfig_raidbuffs", e_panel, "OptionsCheckButtonTemplate")
  2. e_raidbuffs:SetPoint("TOPLEFT", 316, -190)
  3.  
  4. e_raidbuffs:SetScript("OnClick", function(frame)
  5.  
  6. if EndzeitUIOptions then
  7.         if frame:GetChecked() then
  8.             PlaySound("igMainMenuOptionCheckBoxOn")
  9.             EndzeitUIOptions["raidbuffs"] = true
  10.            
  11.         else
  12.             PlaySound("igMainMenuOptionCheckBoxOff")
  13.             EndzeitUIOptions["raidbuffs"] = false
  14.        
  15.         end
  16.     end
  17.    
  18. end)
  19. local e_raidbuffsText = e_raidbuffs:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  20. e_raidbuffsText:SetPoint("LEFT", e_raidbuffs, "RIGHT", 0, 1)
  21. e_raidbuffsText:SetText("Raidbuffs anzeigen")
  22.  
  23. -- buff: bloodlust
  24. local e_bloodlust = CreateFrame("CheckButton", "EndzeitUIConfig_bloodlust", e_panel, "OptionsCheckButtonTemplate")
  25. e_bloodlust:SetPoint("TOPLEFT", 326, -215)
  26.  
  27. e_bloodlust:SetScript("OnClick", function(frame)
  28.  
  29. if EndzeitUIOptions then
  30.         if frame:GetChecked() then
  31.             PlaySound("igMainMenuOptionCheckBoxOn")
  32.             EndzeitUIOptions["bloodlust"] = true
  33.            
  34.         else
  35.             PlaySound("igMainMenuOptionCheckBoxOff")
  36.             EndzeitUIOptions["bloodlust"] = false
  37.        
  38.         end
  39.     end
  40.    
  41. end)
  42. local e_bloodlustText = e_bloodlust:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  43. e_bloodlustText:SetPoint("LEFT", e_bloodlust, "RIGHT", 0, 1)
  44. e_bloodlustText:SetText("Kampfrausch / Heldentum")
  45.  
  46.  
  47. -- buff: legendary
  48. local e_legendary = CreateFrame("CheckButton", "EndzeitUIConfig_legendary", e_panel, "OptionsCheckButtonTemplate")
  49. e_legendary:SetPoint("TOPLEFT", 326, -240)
  50.  
  51. e_legendary:SetScript("OnClick", function(frame)
  52.  
  53. if EndzeitUIOptions then
  54.         if frame:GetChecked() then
  55.             PlaySound("igMainMenuOptionCheckBoxOn")
  56.             EndzeitUIOptions["legendary"] = true
  57.            
  58.         else
  59.             PlaySound("igMainMenuOptionCheckBoxOff")
  60.             EndzeitUIOptions["legendary"] = false
  61.        
  62.         end
  63.     end
  64.    
  65. end)
  66. local e_legendaryText = e_legendary:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  67. e_legendaryText:SetPoint("LEFT", e_legendary, "RIGHT", 0, 1)
  68. e_legendaryText:SetText("Legendary Ring")

this 3 example buttons.
  Reply With Quote
08-21-15, 12:11 AM   #2
VincentSDSH
Non-Canadian Luzer!
 
VincentSDSH's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2006
Posts: 350
CheckButton:disable() / :enable() should disable/enable the CheckButton frame as CheckButton inherits all of the Button methods (as well as those from Frame, Region, and UIObject).
  Reply With Quote
08-21-15, 07:44 AM   #3
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Hi, take a look at BlizzardOptionsPanel_SetupDependentControl function code in OptionsPanelTemplates.lua file and how they utilize it.
__________________
  Reply With Quote
08-21-15, 10:27 AM   #4
Endzeit
A Deviate Faerie Dragon
Join Date: Aug 2015
Posts: 12
okay.. i dont get it, i think i'm too stupid or too inexperienced...

also have a problem with accessing the global savevariables outside functions.
e.g.
inside functions()
EndzeitUIOptions.raidbuffs returns false or true

outside functions()
EndzeitUIOptions.raidbuffs returns nil

SavedVariables\EndzeitUI.lua
Lua Code:
  1. EndzeitUIOptions = {
  2.     ["raidbuffs"] = true,
  3.     ["legendary"] = true,
  4.     ["bloodlust"] = true,
  5.     ["targetmsg"] = true,
  6.     ["xmog"] = true,
  7.     ["targetplayer"] = true,
  8.     ["cursor"] = true,
  9.     ["targetnpc"] = true,
  10. }
  Reply With Quote
08-21-15, 11:06 AM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
You are acccessing the saved variables before they've been loaded.

You should do this in an event like ADDON_LOADED (after checking it's your addon that has been loaded) or PLAYER_LOGIN.

Edit: The reason it is working inside the function is because the function itself isn't being called until during or after the events I mentioned.

Originally Posted by Endzeit View Post
okay.. i dont get it, i think i'm too stupid or too inexperienced...

also have a problem with accessing the global savevariables outside functions.
e.g.
inside functions()
EndzeitUIOptions.raidbuffs returns false or true

outside functions()
EndzeitUIOptions.raidbuffs returns nil

SavedVariables\EndzeitUI.lua
Lua Code:
  1. EndzeitUIOptions = {
  2.     ["raidbuffs"] = true,
  3.     ["legendary"] = true,
  4.     ["bloodlust"] = true,
  5.     ["targetmsg"] = true,
  6.     ["xmog"] = true,
  7.     ["targetplayer"] = true,
  8.     ["cursor"] = true,
  9.     ["targetnpc"] = true,
  10. }
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 08-21-15 at 12:24 PM.
  Reply With Quote
08-21-15, 02:05 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Originally Posted by VincentSDSH View Post
CheckButton:disable() / :enable() should disable/enable the CheckButton frame as CheckButton inherits all of the Button methods (as well as those from Frame, Region, and UIObject).
You can also use button:SetEnabled(boolean) to quickly enable/disable based on a variable.
__________________
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)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Disable Button: if variable == false

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off