WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   change savedvariable over function arg (https://www.wowinterface.com/forums/showthread.php?t=56966)

Syiana 01-10-19 07:56 AM

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 :)

Syiana 01-10-19 09:32 AM

Quote:

Originally Posted by Syiana (Post 331341)
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 :)


All times are GMT -6. The time now is 01:39 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI