Reply
Thread Tools Display Modes
Unread 04-23-13, 03:57 AM   #1
Spawnova
A Black Drake
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 87
simple addon not working

I have an addon I would like to print a line once a certain item is looted/receieved
but it never seems to do anything past "if event=="


Code:
    local SKF = CreateFrame("frame")
	local playerName = UnitName("player")
	local keyName = "Scallions"

    SKF:RegisterEvent("CHAT_MSG_LOOT")
    SKF:SetScript("OnEvent",function(self,event,message)
		if event=="CHAT_MSG_LOOT" then
			local msg = string.gsub(message, "[", "")
                        print "event fired" --never fires
			if string.match(msg,"You receive item: " .. keyName) then
				print "looted"
			end
		end
    end)
Spawnova is offline   Reply With Quote
Unread 04-23-13, 04:32 AM   #2
Resike
A Molten Giant
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 655
Originally Posted by Spawnova View Post
I have an addon I would like to print a line once a certain item is looted/receieved
but it never seems to do anything past "if event=="


Code:
    local SKF = CreateFrame("frame")
	local playerName = UnitName("player")
	local keyName = "Scallions"

    SKF:RegisterEvent("CHAT_MSG_LOOT")
    SKF:SetScript("OnEvent",function(self,event,message)
		if event=="CHAT_MSG_LOOT" then
			local msg = string.gsub(message, "[", "")
                        print "event fired" --never fires
			if string.match(msg,"You receive item: " .. keyName) then
				print "looted"
			end
		end
    end)
print shound be like print("whatever")
Resike is offline   Reply With Quote
Unread 04-23-13, 04:49 AM   #3
Spawnova
A Black Drake
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 87
As far as i know, thats only needed if it contains anything more then string such as variables etc

It works fine without the parentheses
Spawnova is offline   Reply With Quote
Unread 04-23-13, 05:00 AM   #4
Haleth
This Space For Rent
 
Haleth's Avatar
WoWInterface Super Mod
Featured
Join Date: Sep 2008
Posts: 1,173
I'm fairly sure the square bracket is the problem. You need to escape it with %, like so:

Code:
local msg = string.gsub(message, "%[", "")
Haleth is offline   Reply With Quote
Unread 04-23-13, 05:25 AM   #5
Spawnova
A Black Drake
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 87
Originally Posted by Haleth View Post
I'm fairly sure the square bracket is the problem.

Aha you are correct, i had no idea that is one of the magic characters.


EDIT: seemed i also had to match more then the message returned, got it solved now thank you =)

Last edited by Spawnova : 04-23-13 at 05:43 AM.
Spawnova is offline   Reply With Quote
Unread 04-23-13, 06:37 AM   #6
myrroddin
Premium Member
 
myrroddin's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 422
A couple of changes for forward compatibility, and localization...
Lua Code:
  1. local keyName = GetItemInfo(74843) -- returns "Scallions" no matter what locale the game is running
  2. local msg = LOOT_ITEM_PUSHED_SELF -- see GlobalStrings.lua
  3. if string.match(message, msg) then
I may not have the syntax correct on string.match; going from memory. You can merge the second and third lines in my code as well.

Here is a link to GlobalStrings.lua http://wow.go-hero.net/framexml/16650/GlobalStrings.lua
myrroddin is offline   Reply With Quote
Unread 04-23-13, 07:18 PM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,090
It seems like you have Lua errors turned off. It'll be more helpful to you if you turn it on. It'll be in your interface options, I think it's in the last category.
__________________
"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
Unread 04-25-13, 04:20 AM   #8
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,747
If you're developing addons, or even messing with the code of other people's addons, you should really install BugSack. The default error display, even if you turn it on, does not show you errors that occur during the initial loading process, which makes it basically useless for development since this is where most of your errors will occur.

Also, with the default error display you get a giant popup dialog in your face, and your options are (a) deal with the error immediately when it occurs, or (b) close the window and lose it forever; with BugSack you can disable automatic popup and just hear a sound or see a message in the chat frame, and you can look through all the errors that occurred this session, or during previous sessions, at any time.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » simple addon not working

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