Thread Tools Display Modes
07-03-22, 05:55 PM   #1
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
PLAYER_EQUIPMENT_CHANGED unequip / re-equip

Hi all

I need to check a newly equipped items quality, if it is grey save the current equipment set including the new item, if the item is not grey I want to unequip all and then use the current equipment set.
To do this I track the PLAYER_EQUIPMENT_CHANGED event.
Here is my chunk;

Lua Code:
  1. elseif event == "PLAYER_EQUIPMENT_CHANGED" then
  2.             local equipmentSlot = ...
  3.             IronManSelectionFrame:UnregisterEvent("PLAYER_EQUIPMENT_CHANGED") -- unregister so we don't spam the test
  4.             local isItemGrey, itemQuality = true, 99
  5.             itemQuality = GetInventoryItemQuality("player", equipmentSlot)
  6.             if itemQuality ~= 0 then -- if item is not grey
  7.                 isItemGrey = false
  8.                 removeAllEquipedItems()
  9.             end
  10.             if isItemGrey then
  11.                 for k, v in pairs(C_EquipmentSet.GetEquipmentSetIDs()) do
  12.                     C_EquipmentSet.DeleteEquipmentSet(v) -- delete all equipment sets
  13.                 end
  14.                 C_EquipmentSet.CreateEquipmentSet("TESTING", 1035053) -- create new equipment set
  15.             end
  16.             C_EquipmentSet.UseEquipmentSet(0) -- use current equipment set
  17.             print("PLAYER_EQUIPMENT_CHANGED Event Fired", equipmentSlot, isItemGrey, itemQuality) -- debug --
  18.             IronManSelectionFrame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED") -- re-register after test function

I unregister the PLAYER_EQUIPMENT_CHANGED at the start of the function so it doesn’t spam as the unequip re-equip will fire for each item.
He is my result:


Even though I unregister it still spams yet I cannot understand why, so I am looking for some help in understanding why it won't work, and why the equipment set doesn't update.
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
07-03-22, 06:14 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
The system returns the event when the thing happens. You've unregisterd and re-registered the event in a single process and requested x things to happen in between.

It's still processing equipment changes after you re-registered the event.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
07-03-22, 06:41 PM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,919
One of the ways I recall handling this type of recursive callback process in regular programming is to have a variable set when you start processing and then test for that for future calls.

So, something like the following may help, if you can't think of anything wowapi wise.

Lua Code:
  1. -- Addon wide variable ( at top of file )
  2. local isProcessing = false
You might also need to reset this on a reload

And then in your event code
Lua Code:
  1. elseif event == "PLAYER_EQUIPMENT_CHANGED" then
  2.      -- return out immediately if in the middle of an update
  3.      if isProcessing then return end
  4.  
  5.      -- new update, so set processing flag
  6.      isProcessing = true
  7.  
  8.     --------------------------------------------
  9.     -- Rest of your code after this point
  10.    ---------------------------------------------
  11.    
  12.    -- finished processing so reset processing flag
  13.    isProcessing = false
  14.  
  15. end
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 07-03-22 at 06:43 PM.
  Reply With Quote
07-03-22, 08:04 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Possibly use a table with the slots to process and remove them when the corresponding event comes in. Once empty, resume normal processing... something, something a cat...
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
07-03-22, 09:31 PM   #5
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Thanks for the replies.

@Fizzlemizz, I was not sure what you meant here, I hived off the guts of my chunk into its own function that was called when the event fired without success.

@Xrystal, I like what you pointed out here, it triggered a previous issue I had in another addon, however it did not work here.

After playing a bit more I realised that I had overthought the issue, instead of removing all items I simply had to use the saved equipment set.

Here is my new chunk;
Lua Code:
  1. elseif event == "PLAYER_EQUIPMENT_CHANGED" then
  2.             local equipmentSlot = ...
  3.             IronManSelectionFrame:UnregisterEvent("PLAYER_EQUIPMENT_CHANGED") -- unregister so we don't spam the test
  4.             local itemQuality = GetInventoryItemQuality("player", equipmentSlot)
  5.             if itemQuality ~= 7 then -- if item is not grey
  6.                 C_EquipmentSet.UseEquipmentSet(0)
  7.             else
  8.                 for k, v in pairs(C_EquipmentSet.GetEquipmentSetIDs()) do
  9.                     C_EquipmentSet.DeleteEquipmentSet(v) -- delete all equipment sets
  10.                 end
  11.                 C_EquipmentSet.CreateEquipmentSet("TESTING", 1035053)
  12.             end
  13.             print("PLAYER_EQUIPMENT_CHANGED Event Fired", equipmentSlot, itemQuality) -- debug --
  14.             IronManSelectionFrame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED") -- re-register after test function

So the moral of this story is to follow the old KISS maxim.

Thanks for all the help.
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » PLAYER_EQUIPMENT_CHANGED unequip / re-equip

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off