Quantcast
Hookscript - WoWInterface
Thread Tools Display Modes
01-05-22, 04:50 AM   #1
glupikreten
A Cyclonian
Join Date: Apr 2009
Posts: 44
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.
  Reply With Quote
01-05-22, 07:52 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,491
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?
...???
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 01-05-22 at 08:38 AM.
  Reply With Quote
01-05-22, 08:49 AM   #3
glupikreten
A Cyclonian
Join Date: Apr 2009
Posts: 44
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.
  Reply With Quote
01-05-22, 09:35 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,491
The code posted was intended to replace your code, not be used in it .
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
01-05-22, 10:04 AM   #5
glupikreten
A Cyclonian
Join Date: Apr 2009
Posts: 44
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...
  Reply With Quote
01-06-22, 06:08 AM   #6
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 819
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)
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
01-06-22, 09:39 AM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,491
Indeed, I left the T out of the function declaration... oops

Lua Code:
  1. local T = C_Timer.NewTicker(1, function(T)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Hookscript

Thread Tools
Display Modes

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