WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Block Function CastSpellByName (https://www.wowinterface.com/forums/showthread.php?t=58180)

cokedrivers 08-29-20 11:14 AM

Block Function CastSpellByName
 
I have a professions button that i use to open prof1 and prof2 when ever i leftclick for prof1 i get this:
Code:

9x [ADDON_ACTION_FORBIDDEN] AddOn 'BasicUI' tried to call the protected function 'CastSpellByName()'.
[string "@!BugGrabber\BugGrabber.lua"]:519: in function <!BugGrabber\BugGrabber.lua:519>
[string "=[C]"]: in function `CastSpellByName'
[string "@BasicUI\Modules\Datapanel.lua"]:1763: in function <BasicUI\Modules\Datapanel.lua:1752>

Yet if i right click the same button it opens prof2 like it is suppose to.

Here is the code im using:
Code:

                proPlugin:SetScript("OnMouseDown",function(self, button)
                        local prof1, prof2, _, _, _ = GetProfessions()
                        if button == "LeftButton" then
                                if prof1 then       
                                        CastSpellByName((GetProfessionInfo(prof1)))
                                else
                                        print('|cff33ff99BasicUI:|r |cffFF0000No Profession Found!|r')
                                end
                        elseif button == 'MiddleButton' then
                                ToggleSpellBook(BOOKTYPE_PROFESSION)       
                        elseif button == "RightButton" then
                                if prof2 then
                                        CastSpellByName((GetProfessionInfo(prof2)))
                                else
                                        print('|cff33ff99BasicUI:|r |cffFF0000No Profession Found!|r')
                                end
                        end
                end)

Why does the leftbutton throw and error yet the middle and right do not?

Kanegasi 08-29-20 11:19 AM

Try using CastSpell(prof1) instead. GetProfessions() returns spell book indexes which can be fed straight into CastSpell().

cokedrivers 08-29-20 11:35 AM

Quote:

Originally Posted by Kanegasi (Post 336718)
Try using CastSpell(prof1) instead. GetProfessions() returns spell book indexes which can be fed straight into CastSpell().

Nope, i change it to the above and got this error:
Code:

1x BasicUI\Modules\Datapanel.lua:1756: CastSpell(): Invalid spell slot
[string "=[C]"]: in function `CastSpell'
[string "@BasicUI\Modules\Datapanel.lua"]:1756: in function <BasicUI\Modules\Datapanel.lua:1752>

Locals:
(*temporary) = 7


Kanegasi 08-29-20 03:57 PM

I tested the code you provided and all three buttons work for me. The left and right buttons even work in combat, but the middle button does not. I used a piece of a weakaura I have for the button.

Lua Code:
  1. local proPlugin=CreateFrame("Button","proPlugin",UIParent,"ActionButtonTemplate,SecureActionButtonTemplate")
  2. proPlugin:SetSize(32,32)
  3. proPlugin.icon:SetTexture(135912)
  4. proPlugin:SetPoint("CENTER")
  5. proPlugin:EnableMouse(true)
  6. proPlugin:SetScript("OnMouseDown",function(self, button)
  7.     local prof1, prof2, _, _, _ = GetProfessions()
  8.     if button == "LeftButton" then
  9.         if prof1 then  
  10.             CastSpellByName((GetProfessionInfo(prof1)))
  11.         else
  12.             print('|cff33ff99BasicUI:|r |cffFF0000No Profession Found!|r')
  13.         end
  14.     elseif button == 'MiddleButton' then
  15.         ToggleSpellBook(BOOKTYPE_PROFESSION)   
  16.     elseif button == "RightButton" then
  17.         if prof2 then
  18.             CastSpellByName((GetProfessionInfo(prof2)))
  19.         else
  20.             print('|cff33ff99BasicUI:|r |cffFF0000No Profession Found!|r')
  21.         end
  22.     end
  23. end)

cokedrivers 08-30-20 07:51 AM

Quote:

Originally Posted by Kanegasi (Post 336726)
I tested the code you provided and all three buttons work for me. The left and right buttons even work in combat, but the middle button does not. I used a piece of a weakaura I have for the button.

Then it has to be something in my main UI beacuse i still get the same popup:


JDoubleU00 08-30-20 10:33 AM

Quote:

Originally Posted by cokedrivers (Post 336728)
Then it has to be something in my main UI beacuse i still get the same popup:


Have you tried disabling addons and re enabling them one at a time till you find the offending addon?


All times are GMT -6. The time now is 04:40 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI