Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
Advertisement
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Fires when dispatching an event.

(self, event, ...)

Arguments

self
Frame - The registered widget.
event
string - Name of the event.
...
Variable arguments - The event payload, if any.

Details

Examples

Handling several events using if, elseif, else, end:

local frame = CreateFrame("Frame")
frame:SetScript("OnEvent", function(__, event, arg1, arg2, arg3, arg4)
	if event == "PLAYER_LOGIN" then
		print("Logging on")
	elseif event == "PLAYER_REGEN_DISABLED" then
		print("Entering combat")
	elseif event == "PLAYER_REGEN_ENABLED" then
		print("Leaving combat")
	elseif event == "UNIT_SPELLCAST_SENT" and arg1 == "player" and arg4 == 1459 then
		print("Casting arcane intellect")
	end
end)
frame:RegisterEvent("PLAYER_LOGIN")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("UNIT_SPELLCAST_SENT")

Handling several events using a lookup table:

local frame = CreateFrame("Frame")

function frame:PLAYER_LOGIN()
	print("Logging on")
end

function frame:PLAYER_REGEN_DISABLED()
	print("Entering combat")
end

function frame:PLAYER_REGEN_ENABLED()
	print("Leaving combat")
end

function frame:UNIT_SPELLCAST_SENT(unitID, __, __, spellID)
	if (unitID == "player" and spellID == 1459) then
		print("Casting arcane intellect")
    end
end

frame:SetScript("OnEvent", function(self, event, ...)
	self[event](self, ...)
end)

frame:RegisterEvent("PLAYER_LOGIN")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("UNIT_SPELLCAST_SENT")
Advertisement