Reply
 
Thread Tools Display Modes
Unread 12-22-12, 02:59 AM   #1
gmarco
Premium Member
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 97
SendChatMessage and illegal chars

Hi all,

I continue to ask questions on questions and I am sorry about it, but I googled a lot but could not find a solution to this.

I'd like to write something in a CHAT channel. And it works fine, but I was unable to write a something with the escape code to make string colored.

A sample...


Lua Code:
  1. local prgname1 = "|cffffd200addon1|r"
  2. local prgname2 =  "addon2"
  3. local msg1 = string.format("Hello %s !", prgname1)
  4. local msg2 = string.format("Hello %s !", prgname2)
  5.  
  6. print (msg1)
  7. print (msg2)
  8. SendChatMessage(msg1, "GUILD")
  9. SendChatMessage(msg2, "GUILD")

The print(msg?) works quite well but the SendChatMessage only work when the var is prgname2 because in the other case it contains illegal chars.

I check them here: http://www.wowwiki.com/ValidChatMessageCharacters

The problem is that the code doesn't complains but doesn't print either when it found such strings.

I check also:

Lua Code:
  1. SendAddonMessage( "ADDON", "Test", "GUILD" );

But it also don't print either and probably it is not I need.

So the question is ?

Have I to convert the string with some function before passing to SendChatMessage or I have to use different output type ?

Thanks very much for attention as usual.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
gmarco is offline   Reply With Quote
Unread 12-22-12, 05:12 AM   #2
Haleth
This Space For Rent
 
Haleth's Avatar
WoWInterface Super Mod
Featured
Join Date: Sep 2008
Posts: 1,168
You can't send coloured chat messages to other people, only show them for yourself using AddMessage().

SendAddonMessage uses a hidden channel to send data between addons, e.g. to synchronize timers or to check if someone has a newer version.
Haleth is offline   Reply With Quote
Unread 12-22-12, 05:36 AM   #3
gmarco
Premium Member
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 97
Hi, thanks for your reply...

The code is this:

Lua Code:
  1. local prgname = "|cffffd200autopsy|r"
  2.  
  3. local function color(destName)
  4.    if not UnitExists(destName) then return string_format("|cffff0000%s|r", destName) end
  5.    local _, class = UnitClass(destName)
  6.    local color = _G["RAID_CLASS_COLORS"][class]
  7.    return string_format("|cff%02x%02x%02x%s|r", color.r*255, color.g*255, color.b*255, destName)
  8. end
  9.  
  10.         -- begins code on parsing CLEU
  11.  
  12.     local timeStamp, event, _, sourceGUID, sourceName, _, _, destGUID, destName, _, _, prefixParam1, prefixParam2, _, suffixParam1, suffixParam2 = ... 
  13.    
  14.     -- proceed with CLEU handling
  15.     if not playerGUID then
  16.         playerGUID = UnitGUID("player")
  17.     end
  18.    
  19.     if destGUID == playerGUID or (destName and UnitClass(destName)) then
  20.  
  21.     -- prevent the case the sourceName is nil (sometimes it is happened)
  22.     sourceName = sourceName or "Someone"
  23.    
  24.     if event == "SWING_DAMAGE" then
  25.             if prefixParam2 > 0 then
  26.                 print(string_format("%s: [%s] killed [%s] with %s Melee overkill %s", prgname, sourceName, color(destName), prefixParam1, prefixParam2))
  27.                 autopsy_msg = string_format("autopsy: [%s] killed [%s] with %s Melee overkill %s", sourceName, destName, prefixParam1, prefixParam2)
  28.                 SendChatMessage(autopsy_msg, autopsy_chn)
  29.             end
  30.  
  31.          -- proceed with other code and damage types...

The print() works fine and I think I can use as a self output.
The SendChatMessage is not able to to color both the "prgname" nor the color(destName) ...

The only problem of this approach is that I have to deal with 2 different string format for the output if I'd like to mantain the colors in the "self" output.

Btw if can't be solved it is not a problem, so ... :-)

Thanks very much for your kind reply.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
gmarco is offline   Reply With Quote
Unread 12-22-12, 06:27 AM   #4
Haleth
This Space For Rent
 
Haleth's Avatar
WoWInterface Super Mod
Featured
Join Date: Sep 2008
Posts: 1,168
I'm not sure what the problem is now. Like I said, you can't send coloured chat messages to other people.

If you only want to colour the print(), then you should use DEFAULT_CHAT_FRAME:AddMessage() instead. You can provide rgb values in the parameters so you don't need to format the string yourself.
Haleth is offline   Reply With Quote
Unread 12-22-12, 06:46 AM   #5
gmarco
Premium Member
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 97
There wasn't any problems I was only explaining why I asked so I posted the real code :-)

Just to clarify better I post an image:

http://s20.postimage.org/icdo1j1od/autopsy.png

As you can see the print works fine coloring the addon name and the name of the mage pg (Frostanzo).

The SendChatMessage(autopsy_msg, autopsy_chn) instead prints in the default chat color without any color modification for name and pg class.

What I would to obtain was that the SendChatMessage(autopsy_msg, autopsy_chn) can write the same string of the print(), but you said it is not possible so I have to forget to have a colored chat :-)

Thanks very much for your answers.
I really appreciated.
Attached Thumbnails
Click image for larger version

Name:	autopsy.png
Views:	216
Size:	26.1 KB
ID:	7461  
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.

Last edited by gmarco : 12-22-12 at 06:51 AM.
gmarco is offline   Reply With Quote
Unread 12-22-12, 04:02 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,006
Also to add, there are special exceptions such as color codes that are associated with spell and item links as these codes are considered part of the link themselves by the chat server.
__________________
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
SDPhantom is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » SendChatMessage and illegal chars

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