1x BreakItDown-1.0\BreakItDown.lua:66: attempt to call method 'RegisterForEvent' (a nil value)
1x <string>:"BIDFrame1:show()":1: attempt to index global 'BIDFrame1' (a nil value)
<in C code>: in function `RunScript'
Interface\FrameXML\ChatFrame.lua:2118: in function `?':
Interface\FrameXML\ChatFrame.lua:4293: in function `ChatEdit_ParseText':
Interface\FrameXML\ChatFrame.lua:3992: in function `ChatEdit_SendText':
Interface\FrameXML\ChatFrame.lua:4031: in function `ChatEdit_OnEnterPressed':
<string>:"*:OnEnterPressed":1: in function <[string "*:OnEnterPressed"]:1>
Woot! Now I have no bugs! And the slash command works. Now....to make the addon actually do what I'm trying to get it to do.
local myBIDResults = {}
--local texture, item, quantity, quality, locked = GetLootSlotInfo(i);
local function WorkResults()
for i = 1, GetNumLootItems() do
local BIDitemName = GetLootSlotLink(i)
local BIDquantity = select(3, GetLootSlotInfo(i))
if not myBIDResults[BIDitemName] then
myBIDResults[BIDitemName] = {}
end
if myBIDResults[BIDitemName] then
myBIDResults[BIDitemName] = myBIDResults[BIDitemName] + BIDquantity
else
myBIDResults[BIDitemName] = BIDquantity
end
end
end
local function ShowResults()
local text = ""
if myBIDResults > 0 then
for BIDitemName, BIDquantity in pairs(myBIDResults) do
text = BIDitemName.." - "..BIDquantity"\n"
end
end
fontString:SetText(text)
end
I've done plenty of VB coding but I have no idea how to translate it into WoW lua speak. Now I commented out one of the lines because it was creating an error. I assumed it was due to the fact I don't have to have it there. It was just in the original coding I'm dissecting.
Not knowing what is it that you want it to do exactly, I can only give you a few pointers on that code.
local myBIDResults = {}
--local texture, item, quantity, quality, locked = GetLootSlotInfo(i);
local function WorkResults()
for i = 1, GetNumLootItems() do
local BIDitemName = GetLootSlotLink(i)
local BIDquantity = select(3, GetLootSlotInfo(i))
if not myBIDResults[BIDitemName] then
myBIDResults[BIDitemName] = {}
end
if myBIDResults[BIDitemName] then
myBIDResults[BIDitemName] = myBIDResults[BIDitemName] + BIDquantity
else
myBIDResults[BIDitemName] = BIDquantity
end
end
end
Since you assign an empty table to myBIDResults[BIDitemName] if it doesn't exist, it will always pass the 'if myBIDResults[BIDitemName] then' check just below, so you should change one of those. Probably not assigning a table value to it, since you (normally) can't perform arithmetics on tables. (myBIDResults[BIDitemName] + BIDquantity)
local function ShowResults()
local text = ""
if myBIDResults > 0 then
for BIDitemName, BIDquantity in pairs(myBIDResults) do
text = BIDitemName.." - "..BIDquantity"\n"
end
end
fontString:SetText(text)
end
'myBIDResults > 0' is comparing a table to a number, which will error. Instead, what you'll want to do if compare the length (size) of the table, like so: '#myBIDResults > 0'. However that won't actually be necessary in this case since the pairs loop will simply not run if the table length is 0. Finally, you're not actually appending text to the full string, but rather replacing the string on every iteration. You probably want to do something like:
text = text.."\n"..BIDitemName.." - "..BIDquantity
As for what I'm wanting to show, I'd like to show the results of a session of milling/DE'ing/prospecting in a simple window. For example, if I need to prospect 30 stacks of ore for my guild and I forgot to check my bags for gems first. It'd be nice to have a simple visual to check and see what I've done. I found an old addon which did something similar but to the tooltip. I'm just trying to modify it and update it.
So what I'd end up seeing at the end of a boring day of clicking:
Amberjewel - 4
Carnelian - 12
Ember Topaz - 3
Zephyrite - 22
If I was more advanced at Addon coding, I'd love to see it sorted by gem type. Granted, if I was making it for just Cata and above mats, I could probably make a big framework of individual font strings. I'm hoping to also make it user friendly for lower levels just for fun.
So my two variables would be BIDItemName and BIDQuantity. Mostly I replaced information from a very old addon to update it and change how it works slightly. So far it seems I should have just started from scratch. Either way, I'd like to be able to create an array of the items looted and their quantity and then show them in a fontstring on the frame. The quantity numbers would be updated until the player hits the reset button.
Okay, I have almost everything working. Anyone know of a good source to explain Metatables? I'm pretty sure it's the only way I'll be able to update the values of my keys in the array table. It'd be so much easier if it would just allow me to add....
I haven't really been following this thread recently, but the code problem was nagging at me, so I solved it. The attached file does everything you described wanting to do. Feel free to use any/all of it if you want, or just look at it to see how it works.
If put in an addon with SavedVariables: BreakItDownDB in the TOC, the results window will save its position between sessions (you can drag it around by its title). I didn't write any UI for the other options. Items in the list window show tooltips on mouseover. Alt-right-clicking on an item in the results window will remove it, and ctrl-click and shift-click should work as normal to dressup or link the item if applicable. Typing "/bid" opens the window, and it will update while it's open if you want to leave it open. It will track everything seen in loot windows for disenchanting, milling, prospecting, herb gathering, and mining. Uncomment the print statements if you want to see in-game what it's doing. Finally, there is a test function; type "/run BreakItDown:Test()", or see the comment at the end of the file for other possible tests.
ForEventI've done plenty of VB coding but I have no idea how to translate it into WoW lua speak. Now I commented out one of the lines because it was creating an error. I assumed it was due to the fact I don't have to have it there. It was just in the original coding I'm dissecting.
Since you assign an empty table to myBIDResults[BIDitemName] if it doesn't exist, it will always pass the 'if myBIDResults[BIDitemName] then' check just below, so you should change one of those. Probably not assigning a table value to it, since you (normally) can't perform arithmetics on tables. (myBIDResults[BIDitemName] + BIDquantity)
'myBIDResults > 0' is comparing a table to a number, which will error. Instead, what you'll want to do if compare the length (size) of the table, like so: '#myBIDResults > 0'. However that won't actually be necessary in this case since the pairs loop will simply not run if the table length is 0. Finally, you're not actually appending text to the full string, but rather replacing the string on every iteration. You probably want to do something like:
(also you didn't concatenate the "\n" properly)
So my two variables would be BIDItemName and BIDQuantity. Mostly I replaced information from a very old addon to update it and change how it works slightly. So far it seems I should have just started from scratch. Either way, I'd like to be able to create an array of the items looted and their quantity and then show them in a fontstring on the frame. The quantity numbers would be updated until the player hits the reset button.
If put in an addon with SavedVariables: BreakItDownDB in the TOC, the results window will save its position between sessions (you can drag it around by its title). I didn't write any UI for the other options. Items in the list window show tooltips on mouseover. Alt-right-clicking on an item in the results window will remove it, and ctrl-click and shift-click should work as normal to dressup or link the item if applicable. Typing "/bid" opens the window, and it will update while it's open if you want to leave it open. It will track everything seen in loot windows for disenchanting, milling, prospecting, herb gathering, and mining. Uncomment the print statements if you want to see in-game what it's doing. Finally, there is a test function; type "/run BreakItDown:Test()", or see the comment at the end of the file for other possible tests.
Edit: I've removed the attached file; if you followed a link to this post, or found it in a search, you can see an updated version here:
https://gist.github.com/Phanx/2e9f77fb210a25dea90f22dfe9abc26f