WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Help rectifying small batch of code 8.0 broke. (https://www.wowinterface.com/forums/showthread.php?t=56433)

Lesteryoung 07-24-18 04:07 PM

Help rectifying small batch of code 8.0 broke.
 
Hi, I've gathered small bits of code from this forum and the WoW forum over the years and 8.0 seems to have broken two bits of code. Would appreciate any help. I'm sure it's a simple fix.

Code 1:

Lua Code:
  1. local f = CreateFrame("Frame")
  2. f:RegisterEvent("LOOT_OPENED")
  3. f:SetScript("OnEvent", function(self, event, ...)
  4.     for i = GetNumLootItems(), 1, -1 do
  5.         local slotType = GetLootSlotType(i)
  6.         local _, _, _, _, locked, isQuestItem = GetLootSlotInfo(i)
  7.         if not locked and (isQuestItem or slotType == LOOT_SLOT_MONEY or slotType == LOOT_SLOT_CURRENCY) then
  8.             LootSlot(i)
  9.         end
  10.     end
  11. end)

This just loots money on mobs.

Code 2:

Lua Code:
  1. hooksecurefunc("TargetFrame_UpdateAuras", function(s)
  2.           local name = s:GetName() .. "Buff"
  3.           for i = 1 ,MAX_TARGET_BUFFS do
  4.                local _, _, _, _, buffType = UnitAura(s.unit, i)
  5.                if buffType == 'Magic' then
  6.                     _G[name .. i .. "Stealable"]:Show()
  7.            end
  8.       end
  9. end)

This just shows the dispel effect around dispellable debuffs on any class/spec.

Both simply don't function since the patch.

Sylen 07-25-18 04:09 AM

I use this for highlighting debuffs

Lua Code:
  1. --Highlight Purgable Magic Buffs on Target and Focus
  2. hooksecurefunc("TargetFrame_UpdateAuras", function(s)
  3.     for i = 1, MAX_TARGET_BUFFS do
  4.         _, ic, _, dT = UnitBuff(s.unit, i)
  5.         if(ic and (not s.maxBuffs or i<=s.maxBuffs)) then
  6.             fS=_G[s:GetName().."Buff"..i.."Stealable"]
  7.             if(UnitIsEnemy(PlayerFrame.unit, s.unit) and dT=="Magic") then
  8.                 fS:Show()
  9.             else
  10.                 fS:Hide()
  11.             end
  12.         end
  13.     end
  14. end)


With some classes getting a dispel for enrage effects back, might want to use this

Lua Code:
  1. --Highlight Purgable Enrage Buffs on Target and Focus
  2. --Enrage effects return an empty string as debuffType
  3. hooksecurefunc("TargetFrame_UpdateAuras", function(s)
  4.     for i = 1, MAX_TARGET_BUFFS do
  5.         _, ic, _, dT = UnitBuff(s.unit, i)
  6.         if(ic and (not s.maxBuffs or i<=s.maxBuffs)) then
  7.             fS=_G[s:GetName().."Buff"..i.."Stealable"]
  8.             if(UnitIsEnemy(PlayerFrame.unit, s.unit) and dT=="") then
  9.                 fS:Show()
  10.             else
  11.                 fS:Hide()
  12.             end
  13.         end
  14.     end
  15. end)

Torhal 07-25-18 11:05 AM

[quote=Sylen;328958]I use this for highlighting debuffs

Lua Code:
  1. _, ic, _, dT = UnitBuff(s.unit, i)


Unless you're declaring these elsewhere prefixed by "local" you're leaking variables into the global scope. There have been a few occasions where Blizzard has accidentally done this themselves, so AddOn code which also was doing this started causing problems by touching the global "_" variable in secure code.

Sylen 07-25-18 11:28 AM

Thanks for pointing this out. I must have missed this one when re-writing my UI for BFA.

Xrystal 07-25-18 04:27 PM

[quote=Torhal;328966]
Quote:

Originally Posted by Sylen (Post 328958)
I use this for highlighting debuffs

Lua Code:
  1. _, ic, _, dT = UnitBuff(s.unit, i)


Unless you're declaring these elsewhere prefixed by "local" you're leaking variables into the global scope. There have been a few occasions where Blizzard has accidentally done this themselves, so AddOn code which also was doing this started causing problems by touching the global "_" variable in secure code.

Yeah, I noticed this same thing with nUI a few years back when it was mentioned in passing. So I added the change during one of the expansion updates.

Lesteryoung 07-25-18 10:45 PM

Just as an update, I tested both of those bits of code individually in isolation, with no other addon(s)/code active. They were working fine pre pre-patch, so something in the API changed. Not sure how to go about finding that out.

PhoenixPower 07-26-18 04:35 AM

It seems like GetLootSlotInfo changed.

7.3.5
Lua Code:
  1. texture, item, quantity, quality, locked, isQuestItem, questId, isActive = GetLootSlotInfo(slot);

8.0
Lua Code:
  1. texture, item, quantity, currencyID, quality, locked, isQuestItem, questId, isActive = GetLootSlotInfo(slot);

This should work.
Lua Code:
  1. local locked, isQuestItem = select(6, GetLootSlotInfo(i))

And for UnitAura they got rid of the 2nd return value (rank)

Lesteryoung 07-26-18 07:55 PM

Quote:

And for UnitAura they got rid of the 2nd return value (rank)
And how would I write that change into the aforementioned code? Just delete the second "_,"?

myrroddin 07-27-18 02:40 AM

Quote:

Originally Posted by Lesteryoung (Post 329056)
And how would I write that change into the aforementioned code? Just delete the second "_,"?

Yes. For all the APIs that have had a return value removed and not replaced, then all the other return values are shifted one position left.
Lua Code:
  1. -- OLD VERSION
  2. local name, rank, itemID, textureID = ExampleAPI()
  3.  
  4. -- NEW VERSION
  5. local name, itemID, textureID = ExampleAPI()


All times are GMT -6. The time now is 02:23 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI