-
Posted by Question1 on Tue, 01 Jun 2010 15:03:47
I have written Bagbuddy from the book, 2nd version. It is completely the same as the downloadable version for chapter 12 here, which works fine, yet mine won't show. He gives me an error when I give a slashcommand, yet there is not a single difference in the codes.
What have I done wrong, or has gone wrong?
-
Posted by jnwhiteh on Tue, 01 Jun 2010 15:56:09
What is the error message you get?
-
Posted by jnwhiteh on Tue, 01 Jun 2010 16:37:39
I went through and looked at things, and there are a few outstanding issues due to publication errors in the book, or logic errors for things like heirlooms items. If you take the code from the Chapter 13 page and make the following changes (with which everything appears to work well again):
In the function
BagBuddy_OnLoad
The filters will not work properly if you have heirloom items, and very few people in WoW have Legendary items. This change maps the sixth button in the row to quality
7
, which is the heirloom quality. Alter this portion of the function to look like the following:-- Create the filter buttons self.filters = {} for idx=0,5 do local button = CreateFrame("CheckButton", "BagBuddy_Filter" .. idx, self, "BagBuddyFilterTemplate") SetItemButtonTexture(button, "Interface\\ICONS\\INV_Misc_Gem_Pearl_03") self.filters[idx] = button if idx == 0 then button:SetPoint("BOTTOMLEFT", 40, 200) else button:SetPoint("TOPLEFT", self.filters[idx-1], "TOPRIGHT", 12, 0) end if idx == 5 then idx = 7 end button.icon:SetVertexColor(GetItemQualityColor(idx)) button:SetChecked(false) button.quality = idx button.glow:Hide() end self.filters[-1] = self.filters[0] self.filters[7] = self.filters[5]
The changes are right above the button.icon line and the very last line. This checks to see if we're creating the last button, and just changes the
idx
variable to be 7 instead of 5. We then use a quick mapping from quality to the actual button, same as we've done for -1 quality.In
BagBuddy_Update
There's a small logic error here due to the return from
GetContainerItemInfo
not accurately reflecting the 'quality' of the item. Instead, we use theGetItemInfo
function which has more consistent returns. Here is the relevant portion of that function.-- Scan through the bag slots, looking for items for bag = 0, NUM_BAG_SLOTS do for slot = 1, GetContainerNumSlots(bag) do local texture, count, locked, qualityBroken, readable, lootable, link = GetContainerItemInfo(bag, slot) if texture then local name, link, quality = GetItemInfo(link) local shown = true if BagBuddy.qualityFilter then shown = shown and BagBuddy.filters[quality]:GetChecked() end if #nameFilter > 0 then local lowerName = name:lower() shown = shown and string.find(lowerName, nameFilter, 1, true) end
The first change is to replace
quality
withqualityBroken
in the call toGetContainerItemInfo
. This 'ignores' the value by assigning it to a local variable that is not likely to be used. Then, once we've determined that there is an item in the slot (by checking thetexture
variable), we fetch the name and the quality of the item using theGetItemInfo
function. This saves us a call later when we fetch the name for the name filter, and gets us the quality return we're looking for.I hope that all makes sense. I've updated the download for Chapter 13 to reflect the changes.
-
Posted by Question1 on Tue, 01 Jun 2010 18:25:39
However much this will help (and it will, no doubt) My problem is not related to the filtering, or so I think. My problem is more or less concentrated in either the slashcommands, or the OnLoad / OnEvent functions. I've taken everything directly from the downloadable files (which I checked, they work) yet when I login and use /bb or /bagbuddy (the standard slashcommands) I just get: type /help to ..
WoW doesn't recoqnize my commands, or I have some issue with the summoned functions. However, I cannot find any difference between my files and the given ones on this site. The amount of character's is the same, and as far as I can see (and I've been checking the last two days for it) there is no difference between the files, besides the size (which I think is different because I use Windows, and not Unix)
I'm not sure which code I should give here, so if you need any to figure this out, ask me for it.
And I can ofcourse use the codes that are downloadable here, but I'd rather work this out to get a bit more knowledge in the programming of these things. Once I start writing my own add-ons, I cannot simply take someone else's code and use that, as there is no other code.
-
Posted by jnwhiteh on Tue, 01 Jun 2010 18:30:45
Post your code on pastey.net and I'll see if I can find any differences. It's almost certainly a typo somewhere.
-
Posted by Question1 on Tue, 01 Jun 2010 20:10:09
http://pastey.net/137159 = .lua, http://pastey.net/137161 = .toc, and http://pastey.net/137160 = .toc
-
Posted by jnwhiteh on Tue, 01 Jun 2010 22:20:18
Your code is throwing an error due to the full stop on line 57, instead of a comma.
-
Posted by Question1 on Wed, 02 Jun 2010 11:34:50
Ah, I see. And yes, it works now. I'm glad it's no major misunderstanding or something, just a simple typo.
Now, to the next chapter!