SendChatMessage is printing nothing
1 Attachment(s)
I am testing and debugging sending myself a whisper. This addon, PriceAnswer, should reply to this whisper
Code:
price N item The debug self:Print() statements on lines 158 & 159 of Core.lua do correctly print prices for valid items, so I know PA is getting valid and correct prices from TSM. However, the following SendChatMessage lines do not reply with anything, and I'm out of ideas why that's the case. Further, I'd hoped to "harden" PA in case someone asked for a price for an invalid item. Code:
price sally Attached is the full PriceAnswer addon, which should work in any release version of the game. PA does require TradeSkillMaster of course. Any ideas why SendChatMessage is not whispering senderName (me, for testing), or how to truly "harden" the addon against invalid items? Edit: here is the TradeSkillMaster Lua API, although I seem to be using it correctly. https://api.tradeskillmaster.com/addon/ |
Don't know what's going on with SendChatMessage() if your debug prints are showing correct information.
Quote:
Another thing I'd add is stop normal chat traffic from being processed, causing your pattern matching to return nils and throw errors further down. |
I want to answer something but the first lines stuck my mind in a loop.
Code:
local addon_folder = "PriceAnswer" Why are you hardcoding your addon name when you can do Code:
local addonName, addonTable = ... Local print has no issue with those. |
1 Attachment(s)
I apologize for trying to sell sally, possibly to gnomes. Anyway, here is the latest zip.
@SDPhantom: using pcall seems to have stopped the error. I'm still testing. @Dridzt: That nonsense has been removed, and was from a much older idea that was retired. Also, I don't see any control characters being sent as part of the strings. "Market 73g57s11c" for example, does not have control characters. Here's what is happening now. Sending price vestige of the eternal to myself sends the debug print, but echoes price vestige of the eternal to myself instead of the price values. This is the same with any item, crafted or not. Sending price sally to myself correctly whispers the syntax use message.... in an infinite loop. :confused: |
I'm not going to install TSM just to test this, but I removed it from .toc and spoofed the TSM_API so the addon loads without errors.
Then I hardcoded outgoingMessageOne = "outgoing message one" outgoingMessageTwo = "outgoing message two" to get rid of the TSM logic. SendChatMessage works absolutely fine. So I'll say again the problem with SendChatMessage is 99.9% that you are getting something back that includes control codes (like colors) and such messages are silently ignored. So it is not SendChatMessage that's broken it's your message. As for the infinite loop, that's a kinda trivial logic bug to fix don't you think :p |
Oh man, I didn't think about colours as being control codes. I will look into that, or write my own number of copper to string code.
|
Quote:
Quote:
Unregistering the event while processing isn't enough because the reply comes back after you have re-registered it as the message takes time to go to the chat server and return. |
I rewrote this function, then saw your reply. I was about to test it, and if it still goes into an infinite loop, I don't know how to stop it, given the delay to the server and back.
Lua Code:
Lua Code:
|
Partial success! If I now send myself a valid item, I do get the prices back in the whisper. However, immediately after that, I get the syntax use whisper in an infinite loop.
When I whisper myself an invalid item, the syntax use goes into infinite loop. Progress LOL. |
To prevent the infinite loop when testing, hook SendChatMessage, save every message you send in a table, then bail out of processing when the event gets those messages. There's a simple trick to figure out if you're the one that used a hooked function with an "unused" argument.
Lua Code:
As for the control characters, there's an obscure function in the UI code that I believe strips them: message = SubstituteChatMessageBeforeSend(message) There's no documentation for it though. |
How about check if the incoming message is actually the command you're listening for?
Also fixes the false triggers I pointed out at least twice. Code:
local incomingMessage, senderName = ... |
Quote:
Your solution is more elegant than mine. |
PriceAnswer is working, much and many thanks to the help in this forumn and on the WowDev Discord. I just got a request to accept the following syntax. The person making the request changed the trigger from "price" to "?", which is fine.
Code:
?[ItemLink] (doesn't work) The best idea I had was adding trim() to the end of the pattern. Code:
local pattern = "^" .. (L[db.trigger]:gsub("(%W)", "%%%1")) .. ("%s*(%d*)%s*(.*)$"):trim() Lua Code:
|
I completely see why removing the space with an itemID will not work, especially if N is passed.
Code:
price 424306 -- 42 4306 would fail |
Code:
local pattern = "^" .. (L[db.trigger]:gsub("(%W)", "%%%1")) .. "%s*(%d*)%s*(.-)%s*$" |
Thank you. I'll give that a whirl as soon as possible.
|
All times are GMT -6. The time now is 09:08 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI