Thread Tools Display Modes
09-22-05, 08:46 AM   #1
gix
A Deviate Faerie Dragon
 
gix's Avatar
Join Date: Sep 2005
Posts: 13
Problem: ChatFrame_OnEvent is called twice

Hello,

one of my addons hooks ChatFrame_OnEvent to catch specific messages (at the moment CHAT_MSG_RAID and CHAT_MSG_WHISPER), do things depending on the sent message and then to eventually call the original ChatFrame_OnEvent (so I can prevent printing the message to the ChatFrame).

Now with 1700 I noticed that my addon's processing is done twice and first I thought it may be an hooking error so I call it twice myself.

Then I disabled all addons in the AddOns.txt file, added Blizzard's FrameXML\ChatFrame.xml and FrameXML\ChatFrame.lua to my Interface directory and changed ChatFrame_OnEvent to something like this:

Code:
function ChatFrame_OnEvent(event)
    ChatFrame1:AddMessage("ChatFrame_OnEvent called: ".. event .." ".. arg1)
(Note: I used arg1 to 10 but that does not matter here.)

Then I restarted the game and whenever I type something, for example "/say test", I get this:

Code:
ChatFrame_OnEvent called: CHAT_MSG_SAY test
[Me] says: test
ChatFrame_OnEvent called: CHAT_MSG_SAY test
The arguments 1 to 10 seem to be the same both of the time.

Do I miss something signifcant here and it is my own fault or did Blizzard change something? My addon addressed at the beginning worked fine before 1700.

Regards
  Reply With Quote
09-22-05, 09:29 AM   #2
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
the events are called when they are received AND sent in the chat window. I believe this to mean that when you type /say test in the chat window and hit enter, it is calling the event because the chat message recieved something from the edit box on the chat window. Then when the message is actually sent out as a say message, it is being called again to notify the system that the message was successfully output...
  Reply With Quote
09-22-05, 09:51 AM   #3
gix
A Deviate Faerie Dragon
 
gix's Avatar
Join Date: Sep 2005
Posts: 13
As I have said I print out arg1 to 10 and it looks like this (arg1 to 10 are joined with a "," and are displayed as an empty string when nil):

Code:
CF_OE hook, CHAT_MSG_RAID, message, Me, Common, , , , 0, 0, , 0
[Raid] [Me]: message
CF_OE hook, CHAT_MSG_RAID, message, Me, Common, , , , 0, 0, , 0

CF_OE hook, CHAT_MSG_GUILD, message, OtherPlayer, Common, , , , 0, 0, , 0
[Guild] [OtherPlayer]: message
CF_OE hook, CHAT_MSG_GUILD, message, OtherPlayer, Common, , , , 0, 0, , 0
So the same effect occurs in raid, guild, say and other channels and it also occurs when someone else sends a message. The args are always the same.

But then for example with SYSTEM I only get it once:
Code:
CF_OE hook, CHAT_MSG_SYSTEM, [OtherPlayer] has come online., , , , , , 0, 0, , 0
[OtherPlayer] has come online.
  Reply With Quote
09-22-05, 11:01 AM   #4
gix
A Deviate Faerie Dragon
 
gix's Avatar
Join Date: Sep 2005
Posts: 13
Or maybe there is a better method to accomplish what I want?
Basically it's a notifier. It looks for messages with a specific prefix and prints those messages together with a sound in the middle of the screen. But the hooked ChatFrame_OnEvent function is called twice and I test there whether a message has the required prefix or not and then call another function that adds the message to a scrollframe. So because of that the message is also added twice to my scrollframe.
I fixed it for now with a table that saves all noticed messages with the time of the last occurence and only processes them further on after a small timeout of 0.1 seconds.
But this is definitely a weird behavior and worked fine with all older versions of wow.
  Reply With Quote
09-22-05, 12:19 PM   #5
Gello
A Molten Giant
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 521
Do you have those going to two windows?

If you hook ChatFrame_OnEvent, it will receive a copy of every line going to every window. So if you have whispers going to two chat windows it will go through ChatFrame_OnEvent twice.
  Reply With Quote
09-22-05, 12:21 PM   #6
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
Good call by Gello, I hadn't thought about that. Maybe try removing all other chat windows (default to one) and see if it only gets called once.

If that is still not fixing the problem, maybe try posting the same question in the official WOW forums. Maybe in the 1.7 changes thread. Hopefully Slouken can shed some light as to why the event is called twice for that event.

I tried posting your question with a link back here, but for some reason the forums are not letting me log in right now
  Reply With Quote
09-22-05, 01:31 PM   #7
gix
A Deviate Faerie Dragon
 
gix's Avatar
Join Date: Sep 2005
Posts: 13
I do not think that this is the reason.
I usually have 4 chatframes up. Left 3 frames together tabbed: one chat log (with everything except combat of course), one with loot/whisper messages and one with "self" combat events and on the right a normal combat log.
So "say", "guild" and "raid" are only active in one window and if the function in question is indeed called for every window then it would be called four times.

I have not tried what happens if I active raid messages in other windows. Thanks for pointing that out. ChatFrame_OnEvent uses this:AddMessage() so I think it is called indeed multiple times but only for windows where the event in question is activated.

I haven't thought about that. If a user receives raid messages in more than window this could break the addon. But it should work with the added spamming protection.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Problem: ChatFrame_OnEvent is called twice

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off