WoW:API Frame SetScript: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
m (Move page script moved page API Frame SetScript to API Frame SetScript without leaving a redirect)
 
(11 intermediate revisions by 10 users not shown)
Line 1: Line 1:
Sets the action handler for this frame or removes the handler with a nil function
{{widgetmethod}}


frame:SetScript(''"handler"'', ''function'');
Sets an event handler for a specific event type for this frame.


----
  frame:SetScript("handler", func)
; ''Arguments:'' : <br>'''"handler"''' is the action to set, i.e. "OnShow" or "OnEvent".<br>'''function''' is the function you want to set for the handler.<br>
----
; ''Example 1:'' :
  for i = 1, 4 do<br> local frame = getglobal("PartyMemberFrame"..i);<br> frame:SetScript("OnShow", function() this:Hide(); end);<br>end


; ''Result:'' : All party frames will be hidden whenever they're shown.
== Parameters ==
=== Arguments ===
:;handler : string - the name of the handler type, like 'OnShow', 'OnClick'.  See [[Widget_handlers]].
:;func : function - the Lua function to call or 'nil' to remove the handler


== Examples ==
for i = 1, 4 do
    local frame = _G["PartyMemberFrame"..i]
    frame:SetScript("OnShow", frame.Hide)
end
Adds an 'OnShow' event handler to all party frames to be called whenever they're shown.


; ''Example 2:'' :
PartyMemberFrame1:SetScript("OnShow", nil)
Removes whatever 'OnShow' handler was set from 'PartyMemberFrame1'.


PartyMemberFrame1:SetScript("OnShow", nil);
== See also ==
 
* {{api|Frame:GetScript|t=w}}
; ''Result:'' : Removes the OnShow handler function of PartyMemberFrame1.
* {{api|Frame:HookScript|t=w}}
 
* [[Widget_handlers]]
{{template:WoW API}}

Latest revision as of 04:45, 15 August 2023

Widget API ← Frame < SetScript

Sets an event handler for a specific event type for this frame.

frame:SetScript("handler", func)

Parameters[edit]

Arguments[edit]

handler
string - the name of the handler type, like 'OnShow', 'OnClick'. See Widget_handlers.
func
function - the Lua function to call or 'nil' to remove the handler

Examples[edit]

for i = 1, 4 do
    local frame = _G["PartyMemberFrame"..i]
    frame:SetScript("OnShow", frame.Hide)
end

Adds an 'OnShow' event handler to all party frames to be called whenever they're shown.

PartyMemberFrame1:SetScript("OnShow", nil)

Removes whatever 'OnShow' handler was set from 'PartyMemberFrame1'.

See also[edit]