UIHANDLER OnEvent

From Wowpedia
Jump to: navigation, search

The OnEvent handler allows a Frame to respond to state changes (Events) to which it registers.

frame:HookScript("OnEvent", function(self, event, ...)
  -- Do something
end);

Arguments

self 
Frame - Reference to the frame who had registered for the event.
event 
String - Full name of the triggered event.
... 
Vararg Function - Variable number of remaining arguments representing the payload of each event.

Examples

The following examples show a frame that responds to many different events, including one with a payload that is transcribed to arg1 through arg4:

local myFrame = CreateFrame("Frame")
myFrame:HookScript("OnEvent", function(__, event, arg1, arg2, arg3, arg4)
  if (event == "PLAYER_LOGIN") then
    -- The player just logged in (payload: none)
  elseif (event == "PLAYER_REGEN_DISABLED") then
    -- The player is about to enter combat (payload: none)
  elseif (event == "PLAYER_REGEN_ENABLED") then
    -- The player just left combat (payload: none)
  elseif (event == "UNIT_SPELLCAST_SENT" and arg1 == "player" and arg4 == "1459") then
    -- I am casting arcane intellect (payload: unit, target, castGUID, spellID)
  end
end);
myFrame:RegisterEvent("PLAYER_LOGIN");
myFrame:RegisterEvent("PLAYER_REGEN_DISABLED");
myFrame:RegisterEvent("PLAYER_REGEN_ENABLED");
myFrame:RegisterEvent("UNIT_SPELLCAST_SENT");

Notes

  • Each event has its own payload, or variable number of arguments, described on that event's own page within Wowpedia