Thread Tools Display Modes
01-10-19, 07:56 AM   #1
Syiana
A Murloc Raider
 
Syiana's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 7
change savedvariable over function arg

Lua Code:
  1. local function SUICreateTXT(text,anchor,point,pos1,pos2, ...)
  2.         SUITXT = SUI:CreateFontString(nil, SUIConfig, "GameFontNormalLarge")
  3.         SUITXT:SetPoint(point, anchor, pos1, pos2)
  4.         SUITXT:SetText(text)
  5.     end
  6.  
  7.     local function SUICreateCB(name,anchor,tooltip,db, ...)
  8.         SUICheckbox = CreateFrame("CheckButton", nil , SUIConfig,"OptionsBaseCheckButtonTemplate")
  9.         SUICheckbox:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -10)
  10.        
  11.         SUICheckbox:SetScript(
  12.             "OnClick",
  13.             function(frame)
  14.                 local tick = frame:GetChecked()
  15.                 db = tick
  16.                 if tick then
  17.                     DEFAULT_CHAT_FRAME:AddMessage(name .. " Enabled", 0, 1, 0)
  18.                     db = true
  19.                 else
  20.                     DEFAULT_CHAT_FRAME:AddMessage(name .. " Disabled", 1, 0, 0)
  21.                     db = false
  22.                 end
  23.             end
  24.         )
  25.         SUICheckbox:SetScript(
  26.             "OnShow",
  27.             function(frame)
  28.                 frame:SetChecked(db)
  29.             end
  30.         )
  31.  
  32.         SUICheckbox:SetScript(
  33.             "OnEnter",
  34.             function(self)
  35.                 GameTooltip:SetOwner(self, "ANCHOR_BOTTOM")
  36.                 GameTooltip:AddLine("test", 248, 248, 255)
  37.                 GameTooltip:Show()
  38.             end
  39.         )
  40.         SUICheckbox:SetScript("OnLeave", GameTooltip_Hide)
  41.  
  42.         text = SUI:CreateFontString(nil, SUIConfig, "GameFontHighlight")
  43.         text:SetPoint("LEFT", SUICheckbox, "RIGHT", 0, 1)
  44.         text:SetText(name)
  45.        
  46.     end
  47.  
  48.     --UI
  49.     SUICreateTXT("UI",SUIConfig,"TOPLEFT",20,-75)
  50.  
  51.     SUICreateCB("Unitframes",SUITXT,"test",SUIDB.UNITFRAMES)
  52.     SUICreateCB("Castbars",SUICheckbox,"test2",SUIDB.CASTBARS)
  53.     SUICreateCB("Keys",SUICheckbox,"test3",SUIDB.KEYS)
  54.     SUICreateCB("Gryphons",SUICheckbox,"test3",SUIDB.KEYS)

hey, i want to change a savedvariable with "db = true" in the "SUICreateCB" function is it not possible or do i something wrong?

hope someone can help me thx

Last edited by Syiana : 01-10-19 at 08:49 AM.
  Reply With Quote
01-10-19, 09:32 AM   #2
Syiana
A Murloc Raider
 
Syiana's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 7
Originally Posted by Syiana View Post
Lua Code:
  1. local function SUICreateTXT(text,anchor,point,pos1,pos2, ...)
  2.         SUITXT = SUI:CreateFontString(nil, SUIConfig, "GameFontNormalLarge")
  3.         SUITXT:SetPoint(point, anchor, pos1, pos2)
  4.         SUITXT:SetText(text)
  5.     end
  6.  
  7.     local function SUICreateCB(name,anchor,tooltip,db, ...)
  8.         SUICheckbox = CreateFrame("CheckButton", nil , SUIConfig,"OptionsBaseCheckButtonTemplate")
  9.         SUICheckbox:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -10)
  10.        
  11.         SUICheckbox:SetScript(
  12.             "OnClick",
  13.             function(frame)
  14.                 local tick = frame:GetChecked()
  15.                 db = tick
  16.                 if tick then
  17.                     DEFAULT_CHAT_FRAME:AddMessage(name .. " Enabled", 0, 1, 0)
  18.                     db = true
  19.                 else
  20.                     DEFAULT_CHAT_FRAME:AddMessage(name .. " Disabled", 1, 0, 0)
  21.                     db = false
  22.                 end
  23.             end
  24.         )
  25.         SUICheckbox:SetScript(
  26.             "OnShow",
  27.             function(frame)
  28.                 frame:SetChecked(db)
  29.             end
  30.         )
  31.  
  32.         SUICheckbox:SetScript(
  33.             "OnEnter",
  34.             function(self)
  35.                 GameTooltip:SetOwner(self, "ANCHOR_BOTTOM")
  36.                 GameTooltip:AddLine("test", 248, 248, 255)
  37.                 GameTooltip:Show()
  38.             end
  39.         )
  40.         SUICheckbox:SetScript("OnLeave", GameTooltip_Hide)
  41.  
  42.         text = SUI:CreateFontString(nil, SUIConfig, "GameFontHighlight")
  43.         text:SetPoint("LEFT", SUICheckbox, "RIGHT", 0, 1)
  44.         text:SetText(name)
  45.        
  46.     end
  47.  
  48.     --UI
  49.     SUICreateTXT("UI",SUIConfig,"TOPLEFT",20,-75)
  50.  
  51.     SUICreateCB("Unitframes",SUITXT,"test",SUIDB.UNITFRAMES)
  52.     SUICreateCB("Castbars",SUICheckbox,"test2",SUIDB.CASTBARS)
  53.     SUICreateCB("Keys",SUICheckbox,"test3",SUIDB.KEYS)
  54.     SUICreateCB("Gryphons",SUICheckbox,"test3",SUIDB.KEYS)

hey, i want to change a savedvariable with "db = true" in the "SUICreateCB" function is it not possible or do i something wrong?

hope someone can help me thx
Code:
	local function SUICreateCB(name,anchor,tooltip,db, ...)
		SUICheckbox = CreateFrame("CheckButton", nil , SUIConfig, "OptionsBaseCheckButtonTemplate")
		SUICheckbox:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -10)
		
		SUICheckbox:SetScript(
			"OnClick",
			function(frame)
				local tick = frame:GetChecked()
				SUIDB[db] = tick
				if tick then
					DEFAULT_CHAT_FRAME:AddMessage(name .. " Enabled", 0, 1, 0)
					SUIDB[db] = true
				else
					DEFAULT_CHAT_FRAME:AddMessage(name .. " Disabled", 1, 0, 0)
					SUIDB[db] = false
				end
			end
		)
		SUICheckbox:SetScript(
			"OnShow",
			function(frame)
				frame:SetChecked(SUIDB[db])
			end
		)

		SUICheckbox:SetScript(
			"OnEnter",
			function(self)
				GameTooltip:SetOwner(self, "ANCHOR_BOTTOM")
				GameTooltip:AddLine(tooltip, 248, 248, 255)
				GameTooltip:Show()
			end
		)
		SUICheckbox:SetScript("OnLeave", GameTooltip_Hide)

		text = SUI:CreateFontString(nil, SUIConfig, "GameFontHighlight")
		text:SetPoint("LEFT", SUICheckbox, "RIGHT", 0, 1)
		text:SetText(name)
		
	end

	--UI
	SUICreateTXT("UI",SUIConfig,"TOPLEFT",20,-75)

	SUICreateCB("Unitframes",SUITXT,"test","UNITFRAMES")
	SUICreateCB("Castbars",SUICheckbox,"test2","CASTBARS")
	SUICreateCB("Keys",SUICheckbox,"test3","KEYS")
works now
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » change savedvariable over function arg

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