1. #1
    Deleted

    [lua] execute a shlash command in lua function

    hey together,

    so i'm working on my UI and having this small little problem.
    button to show or hide recount. this works without any problems.
    but now i wanted a right click functionality.
    idea was born and with it the problem

    Code:
    -- Meter ---------------------------------------------------------------------------
    ------------------------------------------------------------------------------------
    local MyMeterButton = MyAddonButtonTemplate(nil, MyMinimapButton, 60, 18, "LEFT",-67,0)
    MyMeterButton:RegisterForClicks("LeftButtonUp", "RightButtonUp")    
    local s = MyMeterButton:CreateFontString(nil,"ARTWORK")
        s:SetFont("Interface\\Addons\\zMedia\\fonts\\HOOGE.TTF", 14, "OUTLINE")
        s:SetPoint("CENTER", 0, 0)
        s:SetTextColor(1,1,1,1)
        s:SetText("Meter")
    
      
    MyRecountLock = function()
    if Recount:LockWindows(true)
    then
    Recount:LockWindows(false)
    else
    Recount:LockWindows(true)
    end   
    end
    
       
    MyMeterButton:SetScript("OnClick", function(self, button) if button == "LeftButton" then ToggleFrame(Recount_MainWindow) elseif button == "RightButton" then MyRecountLock()  end end)
    
        if cfg.COLORING == "Class" then
                MyMeterButton:SetScript("OnEnter", function(self) s:SetTextColor(c.r,c.g,c.b,1) end)
            elseif cfg.COLORING == "Custom" then
                MyMeterButton:SetScript("OnEnter", function(self) s:SetTextColor(unpack(cfg.CUSTOMColor)) end)
            else
                MyMeterButton:SetScript("OnEnter", function(self) s:SetTextColor(1,1,1,1) end)
        end
    MyMeterButton:SetScript("OnLeave", function(self) s:SetTextColor(1,1,1,1) end)

    thats what i have. last try was this MyRecountLock function but it did not work.
    how can i solve this problem? how cant i add "/recount lock" in my on click script. think thats the easiest solution.

    i'm hope someone can help me

    p.s.
    i know it's slash and not shlash

  2. #2
    Deleted
    Send the text command?

  3. #3
    Deleted
    if i would know how to send the text command via script, this thread would not exist.
    sry if it's easy for you but i'm no programmer.

  4. #4
    Deleted
    Code:
    local function slashCommand(command,args)
        for key,func in pairs(SlashCmdList) do
            local i = 1
            local c = _G[("SLASH_%s1"):format(key)]
            while c do
                if c == command then
                    func(args)
                    return
                end
                i=i+1
                c = _G[("SLASH_%s%d"):format(key,i)]
            end
        end
    end
    Command should be passed with the slash (so "/recount", not "recount"). Drycoded.

  5. #5
    Code:
    SlashCmdList["RECOUNT"]("lock")
    that will do it

  6. #6
    Deleted
    @SpaceDuck
    tried it lthis way:

    Code:
    MyMeterButton:SetScript("OnClick", function(self, button) if button == "LeftButton" then ToggleFrame(Recount_MainWindow) elseif button == "RightButton" then SlashCmdList["RECOUNT"]("lock") end end)
    LUA Error:
    attempt to call field "RECOUNT" (a nil value) (x2)

    ---------- Post added 2012-11-15 at 06:24 PM ----------

    @Treeston
    thank you it works finely now.
    am i right when i say that i can use that function for any other slash command?


    another big thanks to all that helped me solve my problem

  7. #7
    Deleted
    Should definitely work with every addon-defined slash command. I'm not 100% on all of the default slash commands, though.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •