Thread Tools Display Modes
01-17-10, 02:01 PM   #1
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Can't figure out why this is suddenly not working....

lua Code:
  1. InIg = InIg or CreateFrame("Frame")
  2. InIg:RegisterEvent("VARIABLES_LOADED")
  3. InIg:SetScript("OnEvent", function(self, event, ...) if InIg[event] then return InIg[event](self, event, ...) end end)
  4.  
  5. function InIg:VARIABLES_LOADED(event)  
  6.     self.ignore = self.ignore or {}
  7.     print("self.ignore created")
  8. end
  9.  
  10. -- CHECK IGNORE STATUS
  11. function InIg:ignoreCheck(_,_,sender)
  12.     for i = 1, #(InIg.ignore) do
  13.         if InIg.ignore[i] == sender then
  14.             print(sender.. " is ignored.")
  15.             return true -- sender is on ignore list
  16.         end
  17.     end
  18.     return false -- sender is not on ignore list
  19. end
  20.  
  21. -- HOOK CHATS
  22. local events = {
  23.     "CHAT_MSG_CHANNEL",
  24.     "CHAT_MSG_WHISPER",
  25.     "CHAT_MSG_EMOTE",
  26.     "CHAT_MSG_BATTLEGROUND",
  27.     "CHAT_MSG_BATTLEGROUND_LEADER",
  28.     "CHAT_MSG_GUILD",
  29.     "CHAT_MSG_PARTY",
  30.     "CHAT_MSG_RAID",
  31.     "CHAT_MSG_RAID_LEADER",
  32.     "CHAT_MSG_SAY",
  33.     "CHAT_MSG_RAID_WARNING",
  34.     "CHAT_MSG_YELL",
  35.     "CHAT_MSG_OFFICER"}
  36.    
  37. for _,k in ipairs(events) do
  38.     ChatFrame_AddMessageEventFilter(k, InIg.ignoreCheck)
  39. end

Getting the following error:
Code:
Message: Interface\AddOns\InIg\InIg.lua:67: attempt to get length of field 'ignore' (a nil value)
Time: 01/17/10 13:56:26
Count: 30
Stack: Interface\AddOns\InIg\InIg.lua:67: in function `filterFunc'
Interface\FrameXML\ChatFrame.lua:2511: in function `ChatFrame_MessageEventHandler'
Interface\FrameXML\ChatFrame.lua:2318: in function `ChatFrame_OnEvent'
[string "*:OnEvent"]:1: in function <[string "*:OnEvent"]:1>
Error is at line 12 in my paste above.

I added the print("self.ignore created") and finding that loading seems to be skipping VARIABLES_LOADED because it never prints on login/reload. I've used this setup a dozen times now with no issues, haven't noticed any typos and the frame creation/event registration are the first things to happen in the file.

Last edited by Sythalin : 01-17-10 at 02:03 PM. Reason: code revision, still not helping
  Reply With Quote
01-17-10, 02:56 PM   #2
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Are you using the frame itself as a saved variable?
  Reply With Quote
01-17-10, 02:59 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
First, disable any chat frame addons. Many chat frame addons increase the number of lines retained, which wipes all messages currently in the frame when that action is performed. It's possible your print is occurring but getting wiped.

Second, the error will occur anyway, because your filter function tries to loop through a table the doesn't exist until your VARIABLES_LOADED handler fires, but you're using it to filter messages before that happens.
  Reply With Quote
01-17-10, 03:17 PM   #4
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
No other mods enabled during testing. Golden rule there mate.

That's assuming that chat begins before addons are even loaded, which I'm pretty sure isn't the case. I could be wrong though.
  Reply With Quote
01-17-10, 03:20 PM   #5
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Ah, I see. I missed this on the 3.0 API notes:

Until 3.0, VARIABLES_LOADED used to fire upon completion of the addon loading process; since 3.0, it is fired in response to CVars, Keybindings and other associated "Blizzard" variables being loaded, and may therefore be delayed until after PLAYER_ENTERING_WORLD. The event may still be useful to override positioning data stored in layout-cache.txt
So yes, you would be correct. I'll try moving it to ADDON_LOADED and see what happens.


EDIT: Nope, no dice. Even after hardcoding InIg = {} at the very beginning of the file, still coming up with the same error. And still no message given at "ADDON_LOADED".

EDIT: I set up a seperate saved var than just InIg, seems to be happy now. I've done it the other way before with no issues, but meh. Long as it works.

Last edited by Sythalin : 01-17-10 at 03:41 PM.
  Reply With Quote
01-17-10, 03:44 PM   #6
Starinnia
Ninja Code Monkey
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 84
This prolly isn't going to do anything, but did you try it without the parens around the table when you used the # operator?

Edit: Bah, missed your last edit....
  Reply With Quote
01-17-10, 05:01 PM   #7
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by ChaosInc View Post
EDIT: I set up a seperate saved var than just InIg, seems to be happy now. I've done it the other way before with no issues, but meh. Long as it works.
It might work if you didn't have any functions defined inside the frame as well, or if you defined them inside of your ADDON_LOADED handler, and only used references to the frame rather than a global name (which would get overridden when the saved vars loaded).
  Reply With Quote
01-20-10, 08:03 PM   #8
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Was working on APC today and started getting spammed with chat errors all of a sudden when it worked perfectly on it's last update. Cleared the WTF save files, downloaded my last working version and still getting spammed with errors.

Something has changed and now I'm kinda pissed because I have to go reconfigure half my projects because suddenly this is breaking EVERYTHING.




EDIT: Test further prove that events are being passed up (addon:EVENT() aren't firing), leading me to believe that there's something wrong with my "OnEvent" handler, but ****ed if I know what it is at this point, and I'm too pissed to concentrate on it atm.

Last edited by Sythalin : 01-20-10 at 08:07 PM.
  Reply With Quote
01-20-10, 08:55 PM   #9
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Calmed down now. Sorry for before.

After doing testing to better understand the load up process, I see what you're saying Akryn and finally see where my issue is when trying to use the addon table as the saved variable. Serves me right to try and shortcut things I don't fully understand.

Looks like I'm going to have a bit of work ahead of me to fix this screwup, resulting in people having to delete their saved vars. >.<
  Reply With Quote
01-20-10, 09:00 PM   #10
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Is there anyway you can convert them though ? I managed to do that for one of my addons. Granted it was to merge 2 tables into 1 table but I told it to run when the wrong table was in existence which means the chosen data is fine and now in a format it wants to work with.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
01-20-10, 09:30 PM   #11
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Originally Posted by Xrystal View Post
Is there anyway you can convert them though ? I managed to do that for one of my addons. Granted it was to merge 2 tables into 1 table but I told it to run when the wrong table was in existence which means the chosen data is fine and now in a format it wants to work with.
Been working on that, no success so far. All conversion attempts have been left with ACP_Settings = nil for the new settings until reloading:

lua Code:
  1. if APC then
  2.      APC_Settings = CopyTable(APC["settings"])
  3.      APC = nil
  4. end
  5. -- rest of addon code

lua Code:
  1. if APC then
  2.      APC_Settings = CopyTable(APC["settings"])
  3.     APC = nil
  4.     ReloadUI()
  5. end
  6. -- rest of addon code



EDIT: Correcting mod initials.

Last edited by Sythalin : 01-20-10 at 09:35 PM.
  Reply With Quote
01-20-10, 09:40 PM   #12
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Hmm, probably because you're setting APC to nil which in essence is pointing to the same as the new table. Not sure though as I haven't used CopyTable but thought all variables were by reference.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
01-20-10, 10:01 PM   #13
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Originally Posted by Xrystal View Post
Hmm, probably because you're setting APC to nil which in essence is pointing to the same as the new table. Not sure though as I haven't used CopyTable but thought all variables were by reference.
I used CopyTable on other addons where I've screwed up/changed the saved var format (same as you). Always worked fine. I know why it's not working, but I'm trying to decide if I really want to go through the hassle of creating a second frame to trigger ADDON_LOADED off of the make the fix (since it currently gets overridden, thus never fired) or just have users delete the saved vars. A second frame would require either a reload or a lot of duplicate code to reinstate APC correctly.
  Reply With Quote
01-20-10, 10:06 PM   #14
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Ah, well probably best to get the users to wipe out the files then.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
01-20-10, 11:49 PM   #15
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
You can probably just name the frame something else, and declare the name of the frame as an empty table at the top of your .lua. Then you can use that name as your settings table and not have to change the .toc.
  Reply With Quote
01-21-10, 05:55 AM   #16
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Only tables are passed by reference when assigning variables.

Anyway, the cleanest solution is definitely to use a separate name for your saved variables table as for your addon table. Realistically, your addon table doesn't need to be global at all.

If you really want to use the same name and have a global table, you could do something like this (drycoded):
Code:
local InIg = CreateFrame("Frame") -- local for now, so isn't immediately overwritten when saved variables load
InIg:SetScript("OnEvent", function(self, event, ...) return self[event] and self[event](self, ...) end)
InIg:RegisterEvent("ADDON_LOADED")

function InIg:ADDON_LOADED(addon)
	if addon ~= "InIg" then return end -- change this to match the addon's folder/TOC name!
	
	local db = _G.InIg -- this refers to the global table of your saved variables
	if not db then
		-- create the global table if it doesn't exist yet (first run)
		_G.InIg = {}
		db = _G.InIg
	end

	local function safecopytable(a, b)
		if not a then return {} end
		if not b then b = {} end
		for k,v in pairs(a) do
			if type(v) == "table" then
				b[k] = safecopytable(v, b[k])
			if type(b[k]) ~= type(v) then
				b[k] = v
			end
		end
		return b
	end
	
	safecopytable(db, self) -- values that already exist (eg. functions
							-- defined in the main chunk of this file)
							-- won't be overwritten

	_G.InIg = self -- and now copy back to global namespace
end
  Reply With Quote
01-21-10, 08:10 PM   #17
Recluse
A Cliff Giant
 
Recluse's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 70
Originally Posted by ChaosInc View Post
I used CopyTable on other addons where I've screwed up/changed the saved var format (same as you).
A function I wrote a few years ago to "fix" saved vars when i changed the table layout (and it -is- recursive). Maybe it'll help ya.
lua Code:
  1. --[[
  2. TableMigrate
  3. Notes:  This function accepts two tables.  It ensures that the old table and the new table
  4.     are identical in layout.
  5.     1. Any keys which exist in both tables have their data preserved in the new table.
  6.     2. Any keys which no longer exist in the new table are removed from the old table.
  7.         A. Data which existed in those keys will be lost.
  8.     3. Any keys which do not exist in the old table but do in the new table are added
  9.         A. Newly added keys are given a default value set by the new table.
  10. Reference:
  11.     curT/newT = current and new table.
  12.     curK/newK = current and new key.
  13.     curV/newV = current and new value.
  14. Example Usage:
  15.     myTable = { a = "foo", b = "bar" }
  16.     myDesiredTable = { a = "red", c = "green" }
  17.     TableMigrate(myTable, myDesiredTable)
  18.     result --> myTable = { a = "foo", c = "green" }
  19. ]]
  20. local function TableMigrate(curT, newT)
  21.     --[[First, we need to add keys to the current table which need to be added.
  22.     If a new key is added, we assign the default value provided by the new table passed in.
  23.     After checking, determine if we are looking at a table, and if so, recurse into it.]]
  24.     for newK, newV in pairs(newT) do
  25.         if curT[newK] == nil then
  26.             curT[newK] = newT[newK]
  27.         end
  28.         if (type(newT[newK]) == "table") then
  29.             TableMigrate(curT[newK], newT[newK])
  30.         end
  31.     end
  32.     --[[Second, we need to remove keys and their values which do not exist in the new table.
  33.     After checking, determine if we are looking at a table, and if so, recurse into it.]]
  34.     for curK, curV in pairs(curT) do
  35.         if newT[curK] == nil then
  36.             curT[curK] = nil
  37.         end
  38.         if (type(curT[curK]) == "table") then
  39.             TableMigrate(curT[curK], newT[curK])
  40.         end
  41.     end
  42. end
__________________
We'd be together, but only diamonds last forever...
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Can't figure out why this is suddenly not working....


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