AKtor 0 Report post Posted April 3, 2018 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. 0 Share this post Link to post Share on other sites
WobLight 5 Report post Posted April 3, 2018 In vanilla the script functions take no parameters. OnEvent use the global `event` variable, all other scripts use globals `arg1`, `arg2`, `arg3`, etc. Removing the paramenters of the function should be enough to have something working. Also, global `this` variable is set instead of self. 0 Share this post Link to post Share on other sites
AKtor 0 Report post Posted April 3, 2018 It works, thanks a lot 0 Share this post Link to post Share on other sites