Thread Tools Display Modes
11-04-22, 10:50 AM   #1
NottheSin
A Defias Bandit
Join Date: Nov 2022
Posts: 2
Question 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>
  Reply With Quote
11-04-22, 06:42 PM   #2
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
It would be something like this
Lua Code:
  1. for _, btn in pairs(PetActionBar.actionButtons) do
  2.     hooksecurefunc(btn, "SetHotkeys", HotkeyReplace)
  3. end
  Reply With Quote
11-06-22, 07:46 PM   #3
NottheSin
A Defias Bandit
Join Date: Nov 2022
Posts: 2
Originally Posted by Ketho View Post
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:香蕉:
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » How to fix this error about PetActionButton's Text


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