WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   OnReceiveDrag OnClick scripts on the same button (https://www.wowinterface.com/forums/showthread.php?t=58568)

Walkerbo 01-28-21 10:15 PM

OnReceiveDrag OnClick scripts on the same button
 
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:
  1. local function removeItemFromList(searchList, searchItemLink)
  2.     for k, v in pairs(searchList) do
  3.         if v.itemLink == searchItemLink then
  4.             table.remove(searchList, k)
  5.         end
  6.     end
  7.     if searchList == AVKGlobalSellTable and AVKGlobalSettings.Sell.sirlm then
  8.         print(ColourList.textBluePrefixSuffix .. searchItemLink .. " removed from your global sell list.")
  9.     elseif searchList == AVKCharacterSellTable and AVKGlobalSettings.Sell.sirlm then
  10.         print(ColourList.textBluePrefixSuffix .. searchItemLink .. " removed from " .. playerName .. "'s sell list.")
  11.     elseif searchList == AVKGlobalDestroyTable and AVKGlobalSettings.Destroy.dirlm then
  12.         print(ColourList.textBluePrefixSuffix .. searchItemLink .. " removed from your global destroy list.")
  13.     elseif searchList == AVKCharacterDestroyTable and AVKGlobalSettings.Destroy.dirlm then
  14.         print(ColourList.textBluePrefixSuffix .. searchItemLink .. " removed from " .. playerName .. "'s destroy list.")
  15.     elseif searchList == AVKGlobalProtectTable and AVKGlobalSettings.Protect.pirlm then
  16.         print(ColourList.textBluePrefixSuffix .. searchItemLink .. " removed from your global protect list.")
  17.     elseif searchList == AVKCharacterProtectTable and AVKGlobalSettings.Protect.pirlm then
  18.         print(ColourList.textBluePrefixSuffix .. searchItemLink .. " removed from " .. playerName .. "'s protect list.")
  19.     end
  20. end
  21.  
  22. local function checkItemOnCharacterProtectList(cursorItemID)
  23.     for k, v in pairs(AVKCharacterProtectTable) do
  24.         if v.itemID == cursorItemID then
  25.             return true
  26.         end
  27.     end
  28. end

And here is my onclick script;
Lua Code:
  1. AardvarkSpecialRemoveItemProtectCharacterButton:SetScript(
  2.     "OnClick",
  3.     function(self, button)
  4.         if GetCursorInfo() then
  5.             itemType, itemID, itemLink = GetCursorInfo()
  6.             if itemType ~= "item" then
  7.                 textBoxMessages(InvalidRemove)
  8.             elseif not checkItemOnCharacterProtectList(itemLink) then
  9.                 textBoxMessages(ItemNotFound)
  10.             else
  11.                 removeItemFromList(AVKCharacterProtectTable, itemLink)
  12.             end
  13.         else
  14.             textItemID = AardvarkSpecialRemoveTextBox:GetNumber()
  15.             local itemName, itemLink = GetItemInfo(textItemID)
  16.             C_Timer.After(
  17.                 VariableList.sellDelay,
  18.                 function(self)
  19.                     if itemType ~= "item" then
  20.                         textBoxMessages(InvalidRemove)
  21.                     elseif not checkItemOnCharacterProtectList(itemLink) then
  22.                         textBoxMessages(ItemNotFound)
  23.                     else
  24.                         removeItemFromList(AVKCharacterProtectTable, cursorItemLink)
  25.                     end
  26.                 end
  27.             )
  28.         end
  29.         avkUpdateCharacterProtectList()
  30.         ClearCursor()
  31.     end
  32. )

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:
  1. AardvarkSpecialRemoveItemProtectCharacterButton:SetScript(
  2.     "OnReceiveDrag",
  3.     function(self, button)
  4.         if GetCursorInfo() then
  5.             itemType, itemID, itemLink = GetCursorInfo()
  6.             if itemType ~= "item" then
  7.                 textBoxMessages(InvalidRemove)
  8.             elseif not checkItemOnCharacterProtectList(itemLink) then
  9.                 textBoxMessages(ItemNotFound)
  10.             else
  11.                 removeItemFromList(AVKCharacterProtectTable, itemLink)
  12.             end
  13.         end
  14.         avkUpdateCharacterProtectList()
  15.         ClearCursor()
  16.     end
  17. )
  18. AardvarkSpecialRemoveItemProtectCharacterButton:SetScript(
  19.     "OnClick",
  20.     function(self, button)
  21.         if GetCursorInfo() then
  22.             itemType, itemID, itemLink = GetCursorInfo()
  23.             if itemType ~= "item" then
  24.                 textBoxMessages(InvalidRemove)
  25.             elseif not checkItemOnCharacterProtectList(itemLink) then
  26.                 textBoxMessages(ItemNotFound)
  27.             else
  28.                 removeItemFromList(AVKCharacterProtectTable, itemLink)
  29.             end
  30.         else
  31.             textItemID = AardvarkSpecialRemoveTextBox:GetNumber()
  32.             local itemName, itemLink = GetItemInfo(textItemID)
  33.             C_Timer.After(
  34.                 VariableList.sellDelay,
  35.                 function(self)
  36.                     if itemType ~= "item" then
  37.                         textBoxMessages(InvalidRemove)
  38.                     elseif not checkItemOnCharacterProtectList(itemLink) then
  39.                         textBoxMessages(ItemNotFound)
  40.                     else
  41.                         removeItemFromList(AVKCharacterProtectTable, cursorItemLink)
  42.                     end
  43.                 end
  44.             )
  45.         end
  46.         avkUpdateCharacterProtectList()
  47.         ClearCursor()
  48.     end
  49. )
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.

Vrul 01-29-21 07:45 AM

You are calling checkItemOnCharacterProtectList with an itemLink when in the function itself it is expecting an itemID.

Walkerbo 01-29-21 07:01 PM

Wow, I can't believe I missed that!
I guess that sometimes I get so close to the code I can't see the obvious syntax errors.

Thanks for your help Vrul.


All times are GMT -6. The time now is 06:25 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI