Hi all
I have a couple of issues my code.
I have a list of items that I can add to and remove from.
I am have created a button that can receive an item from a drag-drop, or click-drop or remove and item via it's itemID.
I have a text entry box that will accept itemID's and I can confirm the text entry is working as expected.
I can also confirm the remove item function works as it is used elsewhere in the addon.
When I try to remove an item either by drag-drop, click-drop or via itemID nothing happens.
Bugsack is not detecting any errors.
If I remove the tests that remove function works correctly.
Here are my functions:
Lua Code:
local function removeItemFromList(searchList, searchItemLink)
for k, v in pairs(searchList) do
if v.itemLink == searchItemLink then
table.remove(searchList, k)
end
end
if searchList == AVKGlobalSellTable and AVKGlobalSettings.Sell.sirlm then
print(ColourList.textBluePrefixSuffix .. searchItemLink .. " removed from your global sell list.")
elseif searchList == AVKCharacterSellTable and AVKGlobalSettings.Sell.sirlm then
print(ColourList.textBluePrefixSuffix .. searchItemLink .. " removed from " .. playerName .. "'s sell list.")
elseif searchList == AVKGlobalDestroyTable and AVKGlobalSettings.Destroy.dirlm then
print(ColourList.textBluePrefixSuffix .. searchItemLink .. " removed from your global destroy list.")
elseif searchList == AVKCharacterDestroyTable and AVKGlobalSettings.Destroy.dirlm then
print(ColourList.textBluePrefixSuffix .. searchItemLink .. " removed from " .. playerName .. "'s destroy list.")
elseif searchList == AVKGlobalProtectTable and AVKGlobalSettings.Protect.pirlm then
print(ColourList.textBluePrefixSuffix .. searchItemLink .. " removed from your global protect list.")
elseif searchList == AVKCharacterProtectTable and AVKGlobalSettings.Protect.pirlm then
print(ColourList.textBluePrefixSuffix .. searchItemLink .. " removed from " .. playerName .. "'s protect list.")
end
end
local function checkItemOnCharacterProtectList(cursorItemID)
for k, v in pairs(AVKCharacterProtectTable) do
if v.itemID == cursorItemID then
return true
end
end
end
And here is my onclick script;
Lua Code:
AardvarkSpecialRemoveItemProtectCharacterButton:SetScript(
"OnClick",
function(self, button)
if GetCursorInfo() then
itemType, itemID, itemLink = GetCursorInfo()
if itemType ~= "item" then
textBoxMessages(InvalidRemove)
elseif not checkItemOnCharacterProtectList(itemLink) then
textBoxMessages(ItemNotFound)
else
removeItemFromList(AVKCharacterProtectTable, itemLink)
end
else
textItemID = AardvarkSpecialRemoveTextBox:GetNumber()
local itemName, itemLink = GetItemInfo(textItemID)
C_Timer.After(
VariableList.sellDelay,
function(self)
if itemType ~= "item" then
textBoxMessages(InvalidRemove)
elseif not checkItemOnCharacterProtectList(itemLink) then
textBoxMessages(ItemNotFound)
else
removeItemFromList(AVKCharacterProtectTable, cursorItemLink)
end
end
)
end
avkUpdateCharacterProtectList()
ClearCursor()
end
)
Also, I need to work out how to correctly use two button scripts on the same button.
I need to have the button to get the itemlink of any item drag-dropped or clickdropped.
Also, I need to find out how to have multiple button scripts work together.
I know that I can use :SetScript("OnReceiveDrag", myFunctionToRemoveItemFromList); however, the function that I need to run requires two variables.
I thought I had it correct with the following;
Lua Code:
AardvarkSpecialRemoveItemProtectCharacterButton:SetScript(
"OnReceiveDrag",
function(self, button)
if GetCursorInfo() then
itemType, itemID, itemLink = GetCursorInfo()
if itemType ~= "item" then
textBoxMessages(InvalidRemove)
elseif not checkItemOnCharacterProtectList(itemLink) then
textBoxMessages(ItemNotFound)
else
removeItemFromList(AVKCharacterProtectTable, itemLink)
end
end
avkUpdateCharacterProtectList()
ClearCursor()
end
)
AardvarkSpecialRemoveItemProtectCharacterButton:SetScript(
"OnClick",
function(self, button)
if GetCursorInfo() then
itemType, itemID, itemLink = GetCursorInfo()
if itemType ~= "item" then
textBoxMessages(InvalidRemove)
elseif not checkItemOnCharacterProtectList(itemLink) then
textBoxMessages(ItemNotFound)
else
removeItemFromList(AVKCharacterProtectTable, itemLink)
end
else
textItemID = AardvarkSpecialRemoveTextBox:GetNumber()
local itemName, itemLink = GetItemInfo(textItemID)
C_Timer.After(
VariableList.sellDelay,
function(self)
if itemType ~= "item" then
textBoxMessages(InvalidRemove)
elseif not checkItemOnCharacterProtectList(itemLink) then
textBoxMessages(ItemNotFound)
else
removeItemFromList(AVKCharacterProtectTable, cursorItemLink)
end
end
)
end
avkUpdateCharacterProtectList()
ClearCursor()
end
)
but this too does not work, evedn though I am not getting any errors.
I am really stuck with this one.
Any help would be great.