WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   How to fix this error about PetActionButton's Text (https://www.wowinterface.com/forums/showthread.php?t=59317)

NottheSin 11-04-22 10:50 AM

How to fix this error about PetActionButton's Text
 
I'm using this Lua to replace the hotkey text.
But there is a error in DF.
Can anyone help me to fix it?

Lua Code:
  1. local gsub = string.gsub
  2.  
  3. local function HotkeyReplace(button)
  4.     local text = button.HotKey and button.HotKey:GetText()
  5.     if not text then return end
  6.  
  7.     text = gsub(text, '(s%-)', 's')
  8.     text = gsub(text, '(a%-)', 'a')
  9.     text = gsub(text, '(c%-)', 'c')
  10.     text = gsub(text, '(st%-)', 'c') -- german control 'Steuerung'
  11.  
  12.     for i = 1, 30 do
  13.         text = gsub(text, _G['KEY_BUTTON'..i], 'M'..i)
  14.     end
  15.  
  16.     for i = 1, 9 do
  17.         text = gsub(text, _G['KEY_NUMPAD'..i], 'N'..i)
  18.     end
  19.  
  20.     text = gsub(text, CAPSLOCK_KEY_TEXT, 'CK')
  21.     text = gsub(text, KEY_NUMPADMULTIPLY, '*')
  22.     text = gsub(text, KEY_NUMPADDIVIDE, '/')
  23.     text = gsub(text, KEY_NUMPADPLUS, '+')
  24.     text = gsub(text, KEY_NUMPADMINUS, '-')
  25.     text = gsub(text, KEY_MOUSEWHEELUP, 'MU')
  26.     text = gsub(text, KEY_MOUSEWHEELDOWN, 'MD')
  27.     text = gsub(text, KEY_NUMLOCK, 'NuL')
  28.     text = gsub(text, KEY_PAGEUP, 'PU')
  29.     text = gsub(text, KEY_PAGEDOWN, 'PD')
  30.     text = gsub(text, KEY_SPACE, '_')
  31.     text = gsub(text, KEY_INSERT, 'Ins')
  32.     text = gsub(text, KEY_HOME, 'Hm')
  33.     text = gsub(text, KEY_DELETE, 'Del')
  34.  
  35.     button.HotKey:SetText(text)
  36. end
  37.  
  38. local lgr, lgg, lgb = LIGHTGRAY_FONT_COLOR:GetRGB()
  39. local function SetButtonFont(button)
  40.     if button.HotKey then
  41.         button.HotKey:SetFont(button.HotKey:GetFont(), 12, 'OUTLINE')
  42.         -- update hotkey color
  43.         hooksecurefunc(button.HotKey, 'SetVertexColor', function(self, r, g, b)
  44.             if r == lgr and g == lgg and b == lgb then
  45.                 self:SetVertexColor(1, 1, 1)
  46.             end
  47.         end)
  48.     end
  49.     if button.Name then
  50.         button.Name:SetFont(button.Name:GetFont(), 12, 'OUTLINE')
  51.     end
  52. end
  53.  
  54. local frame = CreateFrame('Frame')
  55. frame:RegisterEvent('PLAYER_LOGIN')
  56. frame:SetScript('OnEvent', function()
  57.     frame:UnregisterEvent('PLAYER_LOGIN')
  58.  
  59.     -- process old buttons
  60.     -- action bar
  61.     for _, button in ipairs(ActionBarButtonEventsFrame.frames) do
  62.         SetButtonFont(button)
  63.         HotkeyReplace(button)
  64.         hooksecurefunc(button, 'UpdateHotkeys', HotkeyReplace)
  65.     end
  66.     -- pet action bar
  67.     for i = 1, 10 do
  68.         local button = _G['PetActionButton' .. i]
  69.         SetButtonFont(button)
  70.         button.HotKey:SetPoint('TOPRIGHT', -1, -4)
  71.         HotkeyReplace(button)
  72.     end
  73.  
  74.     -- action bar
  75.     hooksecurefunc(ActionBarButtonEventsFrame, 'RegisterFrame', function(_, button)
  76.         SetButtonFont(button)
  77.         hooksecurefunc(button, 'UpdateHotkeys', HotkeyReplace)
  78.     end)
  79.     -- pet action bar
  80.     hooksecurefunc('PetActionButton_SetHotkeys', HotkeyReplace)
  81. end)

The error:
Code:

1x Interface/AddOns/HotkeyFont/HotkeyFont.lua:80: hooksecurefunc(): PetActionButton_SetHotkeys is not a function
[string "=[C]"]: in function `hooksecurefunc'
[string "@Interface/AddOns/HotkeyFont/HotkeyFont.lua"]:80: in function <Interface/AddOns/HotkeyFont/HotkeyFont.lua:56>


Ketho 11-04-22 06:42 PM

It would be something like this
Lua Code:
  1. for _, btn in pairs(PetActionBar.actionButtons) do
  2.     hooksecurefunc(btn, "SetHotkeys", HotkeyReplace)
  3. end

NottheSin 11-06-22 07:46 PM

Quote:

Originally Posted by Ketho (Post 341474)
It would be something like this
Lua Code:
  1. for _, btn in pairs(PetActionBar.actionButtons) do
  2.     hooksecurefunc(btn, "SetHotkeys", HotkeyReplace)
  3. end

Thank you so much!
There is no error anymore:香蕉:


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

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