ScriptObject:SetScript

From Warcraft Wiki
Jump to navigation Jump to search

Sets the widget script handler.

ScriptObject:SetScript(scriptTypeName, script)

Arguments

scriptTypeName
string - Name of the script type, for example "OnShow".
script
function|nil - The script handler to call or explicitly nil to remove any existing script.

Details

  • Setting a script will remove any scripts that were previously hooked with HookScript.

Example

Sets the OnEvent script; this prints when your character starts moving.

local function OnEvent(self, event)
	print(event)
end

local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_STARTED_MOVING")
f:SetScript("OnEvent", OnEvent)