I found some code that NiffyKins made a decade ago and I’m trying to re-purpose it as a learning exercise. Unfortunately I’m having trouble and I hope it’s something simple that I’m overlooking.
This addon should fire if someone hugs me, extract their name from the CHAT_MSG_TEXT_EMOTE, and then add their name to a tinsert list. Unfortunately, something is going wrong and I keep getting an error for ‘string expected, got nil’.
Here’s a link to the CHAT_MSG_TEXT_EMOTE entry on gamepedia in case it helps:
https://wow.gamepedia.com/CHAT_MSG_TEXT_EMOTE
HugLogData = {}
local f = CreateFrame('Frame')
f:RegisterEvent('CHAT_MSG_TEXT_EMOTE')
f:SetScript('OnEvent', function(self, event, msg, player)
if msg:match('^%S+ hugs you\.$') then
local playerName
local text = playerName
print(text) --this is the text test line
print("We have a hug!") --another test line
tinsert(HugLogData,format("%s,",text))
end
end)
a) I’m guessing that the problem might have something to do with the function(self, event, msg, player) not having the PlayerName variable of the sender, but every time I try to fix things they just get more broken.
b) Also, I can’t seem to figure out if emote tokens are events or not. I know that EMOTE57_TOKEN (for hug) isn’t localized, which would be great if, say, Spanish or Portuguese speakers ever wanted to do something with this code. But so far that aspect of the api eludes me.
In addition to NiffyKins (on wowhead) I’ve got to give a massive thanks to SDPhantom (wowinterface) and MrFIXlT (curseforge), looking at their references and sample code has helped me understand so much.
My end goal is to eventually make an addon that does the same thing, but tinserts the names of those that attack me, similar to spy. Unfortunately that’s way beyond me right now as it may involve combat events and tinsert list navigation. But once I understand the fundamentals of getting a variable out of an event that’s what I’ll be working on.
Huge thanks to anyone that reads all of this, and I’m sorry for the wall of text. Just writing this down is helping a lot, but any advice from anyone would be a huge help.