Thread Tools Display Modes
03-02-15, 04:12 AM   #1
Leapin
A Defias Bandit
Join Date: Mar 2015
Posts: 3
Misplaced arguments?

So I'm working on my first Lua script and I thought I'd make a simple addon without any XML and without the need of extra frames and stuff, either way, what I am trying to do is whenever someone joins the guild, it will announce in gchat "Welcome name", however, for some reason, the "msg" argument seem to be gone from the function. The event says the args are message, sender, language, channel, target etc etc, but when I try to call the first argument, instead of message, it's sender.

Code:
local gAuto = CreateFrame("Frame")

gAuto:RegisterEvent("CHAT_MSG_GUILD")
gAuto:SetScript("OnEvent", function(self, event, ...)
 self[event](...)
end)

	function gAuto:CHAT_MSG_GUILD(msg, sender, ...) -- msg = senderName instead of message, and sender = language instead of sender name?
		local str = "has joined the guild"
		name = string.gsub(sender, "-TarrenMill", "")
		name = string.gsub(sender, "-Dentarg", "")
		local welcome = "Välkommen "..name.." :)"
		
		--[[
		if string.find(msg, str) then
				SendChatMessage(welcome, "GUILD")
		else
			return
		end
		--]]
	end
I am really lost, I have no idea what I am doing wrong, any help is appreciated
  Reply With Quote
03-02-15, 04:44 AM   #2
Elkano
A Flamescale Wyrmkin
 
Elkano's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2005
Posts: 131
Your call self[event](...) is the culprit. It resullts in the call self.CHAT_MSG_GUILD(...) instead of self:CHAT_MSG_GUILD(...). The latter is equivalent to self.CHAT_MSG_GUILD(self, ...).

So simply changing self[event](...) to self[event](self, ...) should do the trick.
__________________
This posting is made of 100% recycled electrons.
  Reply With Quote
03-02-15, 05:00 AM   #3
Leapin
A Defias Bandit
Join Date: Mar 2015
Posts: 3
Originally Posted by Elkano View Post
Your call self[event](...) is the culprit. It resullts in the call self.CHAT_MSG_GUILD(...) instead of self:CHAT_MSG_GUILD(...). The latter is equivalent to self.CHAT_MSG_GUILD(self, ...).

So simply changing self[event](...) to self[event](self, ...) should do the trick.
That seem to have fixed it, I am still curious, why do we write "self[event]()" instead of "self:event()"?
  Reply With Quote
03-02-15, 05:28 AM   #4
Elkano
A Flamescale Wyrmkin
 
Elkano's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2005
Posts: 131
The following three are equivalent:
- self.event(self)
- self:event()
- self["event"](self)

if however event is a variable (in contrast to the string "event"), your only way of calling is
- self[event]()
__________________
This posting is made of 100% recycled electrons.

Last edited by Elkano : 03-02-15 at 05:49 AM.
  Reply With Quote
03-02-15, 05:39 AM   #5
Leapin
A Defias Bandit
Join Date: Mar 2015
Posts: 3
Originally Posted by Elkano View Post
The following three are equivalent:
- self.event(self)
- self:event()
- self["event"]()

if however event is a variable (in contrast to the string "event"), your only way of calling is
- self[event]()
Ah yes, ofcourse. Thank you

Last edited by Leapin : 03-02-15 at 05:41 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Misplaced arguments?

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