Hi everybody.
I try to write an addon. Need to handle some events, for this I created a frame. In the Internet there are many examples of code similar to this one:
local frame = CreateFrame("Frame");
frame:RegisterEvent("PLAYER_ENTERING_WORLD");
frame:RegisterEvent("PLAYER_REGEN_DISABLED");
frame:RegisterEvent("PLAYER_REGEN_ENABLED");
frame:SetScript("OnEvent", function(self, event, ...)
DEFAULT_CHAT_FRAME:AddMessage("OnEvent"); --[[Message is displayed--]]
if event == "PLAYER_ENTERING_WORLD" then
DEFAULT_CHAT_FRAME:AddMessage("entering the world"); --[[Condition does not triggers --]]
elseif event == "PLAYER_REGEN_DISABLED" then
DEFAULT_CHAT_FRAME:AddMessage("entering combat"); --[[Condition does not triggers--]]
elseif event == "PLAYER_REGEN_ENABLED" then
DEFAULT_CHAT_FRAME:AddMessage("leaving combat"); --[[Condition does not triggers--]]
end;
end);
The frame is created, subscribed to the events, the handler is triggered by these events, but the conditions in the handler do not work. What am I doing wrong?
However, everything works if I create a frame through XML, and there I hang a handler function on it. I can stop at this, but curiosity does not give rest - why the above code does not work?
Thanks for any help.