WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   SendChatMessage help (https://www.wowinterface.com/forums/showthread.php?t=39971)

weasoug 05-03-11 05:39 AM

SendChatMessage help
 
HEY ALL, I have seen this 1 time but now a few others have, on my autoress code you get an error, it seems to be to do with the SendChatMessage when in combat, a message will say cant till xamount of time.

Code:

1x SendChatMessage(): Invalid escape code in chat message:
<in C code>: ?
<in C code>: in function `SendChatMessage'
wIn1-5.0\wIn1.lua:131: in function `?'
wIn1-5.0\wIn1.lua:617: in function <wIn1\wIn1.lua:616>

Locals:
(*temporary) = "Thanks for the rez! I still have 14 |4second:seconds; until I can accept it."
(*temporary) = "WHISPER"
(*temporary) = nil
(*temporary) = "nameremoved"

the error here seems to be todo with the event hand, of what is not near the main code

Code:

        local frame = CreateFrame('Frame')
        frame:Hide()

        for event, handler in pairs(eventHandlers) do
                frame[event] = handler
                frame:RegisterEvent(event)
                eventHandlers[event] = nil
        end

        frame:SetScript('OnEvent', function(self, event, ...)
                self[event](...)
        end)

but the error it self


Code:

        eventHandlers['RESURRECT_REQUEST'] = function(name)
                if not (UnitAffectingCombat('player') or UnitAffectingCombat(name)) then
                        local delay = GetCorpseRecoveryDelay()
                        if delay == 0 then
                                AcceptResurrect()
                                DoEmote('thank', name)
                        else
                                SendChatMessage(("Thanks for the rez! I still have %d |4second:seconds; until I can accept it."):format(delay), 'WHISPER', nil, name)
                        end
                end
        end

anyhelp would be great, thanks

Rilgamon 05-03-11 05:55 AM

"|" is a special character, not sure what you need it for in your string :)

weasoug 05-03-11 06:30 AM

Quote:

Originally Posted by Rilgamon (Post 236433)
"|" is a special character, not sure what you need it for in your string :)

ahh maybe like %d 4second:seconds;

im not sure why that is there. im sure i read something about use it.

Ketho 05-03-11 06:35 AM

I also had problems with using grammar UI escape sequences in SendChatMessage, for the same pipe character "|" reason that Rilgamon just explained

Dridzt has posted a workaround for setting and grabbing the formatted text from a frame
Code:

local b = CreateFrame("Button")
Code:

        eventHandlers['RESURRECT_REQUEST'] = function(name)
                if not (UnitAffectingCombat('player') or UnitAffectingCombat(name)) then
                        local delay = GetCorpseRecoveryDelay()
                        if delay == 0 then
                                AcceptResurrect()
                                DoEmote('thank', name)
                        else
                                local formattedText = b:GetText(b:SetFormattedText("%d |4second:seconds;", delay))
                                SendChatMessage("Thanks for the rez! I still have "..formattedText.." until I can accept it.", 'WHISPER', nil, name)
                        end
                end
        end


weasoug 05-03-11 07:01 AM

oh nice one. i will try this out. if i put the local b = CreateFrame("Button")
in with the code. it should work out right.

Code:

        eventHandlers['RESURRECT_REQUEST'] = function(name)
                if not (UnitAffectingCombat('player') or UnitAffectingCombat(name)) then
                        local delay = GetCorpseRecoveryDelay()
                        if delay == 0 then
                                AcceptResurrect()
                                DoEmote('thank', name)
                        else
                                local b = CreateFrame("Button")
                                local formattedText = b:GetText(b:SetFormattedText("%d |4second:seconds", delay))
                                SendChatMessage("Thanks for the rez! I still have "..formattedText.." until I can accept it.", 'WHISPER', nil, name)
                        end
                end
        end


Vlad 05-03-11 07:24 AM

I do have one question, why use that method?

All it does is return "%d seconds" and all that again does is put the GetCorpseRecoveryDelay() value (number) so it is "0 seconds", wouldn't it just be easier to do this?

Code:

eventHandlers['RESURRECT_REQUEST'] = function(name)
  if UnitAffectingCombat("player") or UnitAffectingCombat(name) then return end

  local delay = GetCorpseRecoveryDelay()
  if delay == 0 then
    AcceptResurrect()
    DoEmote("thank", name)
  else
    SendChatMessage("Thanks for the rez! I still have "..delay.." seconds until I can accept it.", "WHISPER", nil, name)
  end
end

Maybe I am missing something. :(

weasoug 05-03-11 07:42 AM

Quote:

Originally Posted by Vladinator (Post 236441)
I do have one question, why use that method?

All it does is return "%d seconds" and all that again does is put the GetCorpseRecoveryDelay() value (number) so it is "0 seconds", wouldn't it just be easier to do this?

Code:

eventHandlers['RESURRECT_REQUEST'] = function(name)
  if UnitAffectingCombat("player") or UnitAffectingCombat(name) then return end

  local delay = GetCorpseRecoveryDelay()
  if delay == 0 then
    AcceptResurrect()
    DoEmote("thank", name)
  else
    SendChatMessage("Thanks for the rez! I still have "..delay.." seconds until I can accept it.", "WHISPER", nil, name)
  end
end

Maybe I am missing something. :(

I see what you mean. but unsure, as i have not used that way. i will give it ago. thanks for the tip.

Xinhuan 05-03-11 07:54 AM

Because

"%d |4second:seconds;"

will automatically select "second" or "seconds" depending on the number in %d.

Vlad 05-03-11 07:59 AM

I did not know that Xinhuan, thanks!

"|#A:B;" I guess where A is single form and B is plural form. What does the "4" mean? But what does # do? Is there some sort of lexicon over the type of "|...;" you can create?

Trying to figure if it's something to WoW LUA only or if regular LUA also supports such syntaxes in strings.

Xubera 05-03-11 08:06 AM

|1 is used is to choose the word if the preceding number is a 1 or 0

|1steve;frank; will return steve for any number ending in 1 or 0 (0,1, 10,11, 20,21...)

|2 is really for french i think, will change de to d' and remove the space if the next word starts with a vowel

|3 is for German,

and |4 is singular/plural detector

|4second:seconds; for proper word choosing

Xinhuan 05-04-11 11:14 AM

Quote:

Originally Posted by Vladinator (Post 236445)
Trying to figure if it's something to WoW LUA only or if regular LUA also supports such syntaxes in strings.

Xubera has them. They are WoW specific escapes.


All times are GMT -6. The time now is 10:39 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI