WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Hooking Scripts on game frames (https://www.wowinterface.com/forums/showthread.php?t=59103)

dafou 04-20-22 06:12 PM

Hooking Scripts on game frames
 
Hey everyone,

I’m trying to work on addons and I’m running into an issue.

When trying to hook a function onto an existing frame OnShow like “SouldbindViewer”, “GarrisonLandingPage” or “PlayerTalentsFrame”, it simply doesn’t work.

But it does work on my custom Frames or on other Frames like “ChatFrame1”.

I’m wondering if I’m missing something here ?

Fizzlemizz 04-20-22 08:25 PM

Those all seem to be frames from Load On Demand addons so you're probably trying to hook them before they exist.

What you need to do is find the Blizzard addon they belong to.
Create a frame and register it to recieve the ADDDON_LOADED event.
Check which addon loaded and if it's one of yours, hook the script eg.

Lua Code:
  1. local f = CreateFrame("Frame")
  2. f:RegisterEvent("ADDON_LOADED")
  3. f:SetScript("OnEvent", function(self, event, addonname)
  4.     if addonname == "Blizzard_GarrisonUI" then
  5.         GarrisonLandingPage:HookScript("OnShow", function(self)
  6.             -- do whatever
  7.         end)
  8.     elseif addonname == "One of the other addons" then
  9.         -- do whatever else
  10.     end
  11. end)

dafou 04-21-22 06:55 AM

Ooooh I see this makes way more sense !

This worked and I found a list of all Blizzard addons to check if they load with them.

Thank you for the quick reply, all I did was to wait for VARIABLES_LOADED but I didn't know these were part of addons :)


All times are GMT -6. The time now is 08:08 PM.

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