Wowpedia

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

READ MORE

Wowpedia
Advertisement

Registers the frame to an event.

registered = Frame:RegisterEvent(eventName)

Arguments[]

eventName
string - Name of the frame event.

Returns[]

registered
boolean - Returns true if the frame is successfully registered to the event. Returns false if the frame was already registered to this event. Throws an error if the event is invalid.

Example[]

-- Create a frame
local f = CreateFrame("Frame")

-- Register events
f:RegisterEvent("CHAT_MSG_CHANNEL")
f:RegisterEvent("PLAYER_STARTED_MOVING")
f:RegisterEvent("PLAYER_STOPPED_MOVING")

-- Set the OnEvent script handler 
f:SetScript("OnEvent", function(self, event, ...)
	if event == "CHAT_MSG_CHANNEL" then
		local msg, playerName = ...
		print(event, msg, playerName)
	elseif event == "PLAYER_STARTED_MOVING" then
		print("You started moving")
	elseif event == "PLAYER_STOPPED_MOVING" then
		print("You stopped moving")
	end
end)

In-Depth Details[]

Event frames are generally notified in the order they were first registered. Holes get up filled up eagerly from the back. Insertions are always at the back.[1]

local f1 = CreateFrame("Frame")
f1:SetScript("OnEvent", function() print("Frame 1") end)
f1:RegisterEvent("PLAYER_ENTERING_WORLD")

local f2 = CreateFrame("Frame")
f2:SetScript("OnEvent", function() print("Frame 2") end)
f2:RegisterEvent("PLAYER_ENTERING_WORLD")

local f3 = CreateFrame("Frame")
f3:SetScript("OnEvent", function() print("Frame 3") end)
f3:RegisterEvent("PLAYER_ENTERING_WORLD")
-- 1, 2, 3

f2:UnregisterEvent("PLAYER_ENTERING_WORLD") -- hole of 2 gets filled up by 3
-- 1, 3

local f4 = CreateFrame("Frame")
f4:SetScript("OnEvent", function() print("Frame 4") end)
f4:RegisterEvent("PLAYER_ENTERING_WORLD")
-- prints 1, 3, 4

Patch changes[]

Battle for Azeroth Patch 8.0.1 (2018-07-17): Registering a non-existing event now raises an error instead of returning nil.[2]

Advertisement