WoWInterface

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

glupikreten 01-05-22 04:50 AM

Hookscript
 
Hi,

quick 2 questions:

1. how can you remove hookscript from frame upon some condition?
2. what is the best way to wait for some frame to show in UI... and i dont mean to Show() when already exists.. i mean to get it when it is created regardless of its visibility state?

i want this:

Code:

UIParent:HookScript(
        "OnUpdate",
        function(self)

                if CUSTOMFRAME then
                        CUSTOMFRAME:HookScript(
                                "OnUpdate",
                                function(self)
                                        print("have it")
                                end
                        )
                       

                      UNHOOK UIPARENT BECAUSE I FOUND FRAME
                end
        end
)


Thank you.

Fizzlemizz 01-05-22 07:52 AM

You can't unkook something, just alter what the hook function does,

You could use OnUpdate on a frame of your own and when the CUSTOMFRAME is found, hide your frame (that stops it's OnUpdate from running) or set it's OnUpdate script to nil.

Maybe something like:
Lua Code:
  1. local T = C_Timer.NewTicker(1, function()
  2.     if CUSTOMFRAME then
  3.         CUSTOMFRAME:HookScript("OnUpdate", function(self)
  4.             print("have it")
  5.         end)
  6.         T:Cancel()
  7.     end
  8. end)

There are probably other possabilities depending on what other conditions might exist

Is the frame in a Load-On-Demand addon?
Is there another frame/function that creates the frame that you can hook?
...???

glupikreten 01-05-22 08:49 AM

That code return error... saying T is not found... i just put self:Cancel() instead...

In any case thank you.. i managed to get it working.

Fizzlemizz 01-05-22 09:35 AM

The code posted was intended to replace your code, not be used in it :eek:.

glupikreten 01-05-22 10:04 AM

Yes... i know... and when i drop just that piece of code you posted i get error cuz T is uknown variable (at least in classic SoM client)... dunno scope issues or what.. im not wow lua developer.. i just dabble with it to customize my ui...

Rilgamon 01-06-22 06:08 AM

From https://github.com/tomrus88/Blizzard...merAugment.lua I'd guess the callback gets called with the right object to use cancel on. So this should work:

Lua Code:
  1. local T = C_Timer.NewTicker(1, function(self)
  2.         if CUSTOMFRAME then
  3.             CUSTOMFRAME:HookScript("OnUpdate", function(self)
  4.                 print("have it")
  5.             end)
  6.             self:Cancel()
  7.         end
  8.     end)

Fizzlemizz 01-06-22 09:39 AM

Indeed, I left the T out of the function declaration... oops

Lua Code:
  1. local T = C_Timer.NewTicker(1, function(T)


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

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