ScriptObject:HookScript()

From Wowpedia
Jump to: navigation, search

Securely post-hooks a script handler.

success = ScriptObject:HookScript(scriptType, handler [, bindingType])

Arguments

scriptType 
string - Name of the script type, e.g. "OnShow".
handler 
function - The function to call; will be passed all arguments relevant for the hooked frame script type.
bindingType 
number?Optional. Could be nil. - Specifies any intrinsic frame's pre/post handler to hook.
Value Enum Description
0
LE_SCRIPT_BINDING_TYPE_INTRINSIC_PRECALL
1
LE_SCRIPT_BINDING_TYPE_EXTRINSIC Default
2
LE_SCRIPT_BINDING_TYPE_INTRINSIC_POSTCALL

Returns

success 
boolean - Returns true if the hook was successfully installed, false if not.

Details

  • If the widget script type doesn't have an existing handler function, one will be created as if you called ScriptObject:SetScript()
  • An intrinsic Frame can have irrevocable pre/post handlers. These cannot be set or changed, but they can be securely post-hooked using bindingType[1]. Hooking a nonexistent pre/post handler fails with a return value of false.

Example

Prints when you open the character frame.

/run CharacterFrame:HookScript("OnShow", function(self) print(self:GetName().." was shown") end)

Prints when ChatFrame1 is shown when e.g. switching between chat tabs.

ChatFrame1:HookScript("OnShow", function(self)
	print(self:GetName().." was shown (extrinsic)")
end)

ChatFrame1:HookScript("OnShow", function(self)
	print(self:GetName().." was shown (postcall)")
end, LE_SCRIPT_BINDING_TYPE_INTRINSIC_POSTCALL)

Patch history

See also

External links

References

  1. ^ a b Blizzard Entertainment Ornyx 2016-10-04. Notable UI Changes Coming in 7.1. Archived from the original