Thread Tools Display Modes
10-17-09, 12:32 AM   #1
Cowberty
A Murloc Raider
Join Date: Oct 2008
Posts: 8
help with tables...

I'm getting this error: "bad argument #1 to 'pairs' (table expected, got nil)"

I'm pretty new to working with tables, so maybe I'm just not getting somthing here...

Here's the code:
Code:
local afkPlayerName, afkPlayersList = {}

local function isStillAfk(afkPlayerName) --Just checking if you're still flagged AFK
	for k,v in pairs(afkPlayersList) do
		if k == afkPlayerName and v == "afk" then
		return true
		else
		return false
		end
	end
end

local function findAfkMessage(self, event, msg, player, ...) --Looks for the AFK spam in the chat frame
	if string.find(msg, "is Away From Keyboard:") then
		if not isStillAfk(player) then
		DEFAULT_CHAT_FRAME:AddMessage("|cFFFFC0CB"..player.." is AFK.")
		afkPlayersList[player] = "afk"
		--[[elseif isStillAfk(player) then
		afkPlayerName = player--]]
		end
		return true
	else
		if isStillAfk(player) then
		DEFAULT_CHAT_FRAME:AddMessage("|cFFFFC0CB"..player.." is no longer AFK.")
		end
		afkPlayersList[player] = "not afk"
		return false
	end
end

ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", findAfkMessage)
Any insight you can give me would be great. Thanx
  Reply With Quote
10-17-09, 01:03 AM   #2
wurmfood
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 122
In your first line, you're declaring afkPlayerName as a table and afkPlayersList as nil. I think you mean to do the opposite.
  Reply With Quote
10-17-09, 01:05 AM   #3
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Code:
local afkPlayerName, afkPlayersList = {}
That code is making afkPlayerName into a table and not afkPlayerList. You want to do something more like:
Code:
local afkPlayersList = { }

local function findAfkMessage(_, event, msg, name, ...) --Looks for the AFK spam in the chat frame
	if msg:find("is Away From Keyboard:") then
		if not afkPlayersList[name] then
			afkPlayersList[name] = true
			DEFAULT_CHAT_FRAME:AddMessage("|cFFFFC0CB" .. name .. " is AFK.")
		end
		return true
	else
		if afkPlayersList[name] then
			afkPlayersList[name] = nil
			DEFAULT_CHAT_FRAME:AddMessage("|cFFFFC0CB".. name .. " is no longer AFK.")
		end
		return false
	end
end

ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", findAfkMessage)

Last edited by Vrul : 10-17-09 at 01:33 AM.
  Reply With Quote
10-17-09, 02:33 AM   #4
Cowberty
A Murloc Raider
Join Date: Oct 2008
Posts: 8
Thanks! helped a lot!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » help with tables...


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