OnEvent event is nil

Post Reply
Kex0
Posts: 2

OnEvent event is nil

Post by Kex0 » Wed May 24, 2023 5:57 pm

Here's code example:

Code: Select all

local f = CreateFrame('Frame')
f:RegisterEvent('CHAT_MSG_TEXT_EMOTE')
f:SetScript('OnEvent', function(self, event, msg, player)
    print(event)
    if event == "CHAT_MSG_TEXT_EMOTE" then
        if msg:find('cry') then
            print("crying "..player)
        end
    end
end)
I'm trying to make a simple addon and I want to use events. The problem is that
`event` within `f:SetScript('OnEvent', function(self, event, msg, player)` is always `nil`. As a matter of fact all arguments are always `nil`. The only way I can get past `if event == "CHAT_MSG_TEXT_EMOTE" then` is with this code:

Code: Select all

local f = CreateFrame('Frame')
f:RegisterEvent('CHAT_MSG_TEXT_EMOTE')
f:SetScript('OnEvent', function()
    print(event)
    if event == "CHAT_MSG_TEXT_EMOTE" then
        if msg:find('cry') then
            print("crying "..player)
        end
    end
end)
but then I have no other arguments like `msg` or `player` from `CHAT_MSG_TEXT_EMOTE`

What am I doing wrong? This happens with every event.

Fdx
Posts: 5

Re: OnEvent event is nil

Post by Fdx » Thu May 25, 2023 3:37 pm

You almost got it. Event arguments are supplied as the variables arg1, arg2 etc. See the documentation here: https://wowwiki-archive.fandom.com/wiki ... TEXT_EMOTE

Try the following code instead:

Code: Select all

local f = CreateFrame('Frame')
f:RegisterEvent('CHAT_MSG_TEXT_EMOTE')
f:SetScript('OnEvent', function()
    print(event)
    if event == "CHAT_MSG_TEXT_EMOTE" then
        if string.find(arg1,'cry') then
            print("crying "..arg2)
        end
    end
end)

Kex0
Posts: 2

Re: OnEvent event is nil

Post by Kex0 » Fri May 26, 2023 12:29 pm

Thank you very much!
I was reading just this https://wowpedia.fandom.com/wiki/CHAT_MSG_TEXT_EMOTE
and it has no mention of arg1, arg2, ...

Post Reply