Thread Tools Display Modes
10/21/21, 05:25 AM   #1
Askedal
Join Date: Aug 2017
Posts: 9
Performance Problem with EVENT_LOOT_UPDATED

Hello,

I'm currently working on an update to the SmarterAutoLoot Addon. The Addon currently works like this:

During initialization it is registering for EVENT_LOOT_UPDATED:

Lua Code:
  1. self.control:RegisterForEvent(EVENT_LOOT_UPDATED, function( _, ... ) self:OnLootUpdated( ... )  end)

In the OnLootUpdated function it checks with several rules and options if the item in the loot window should be looted or not.
This all works quite nicely so far, when all the items should be looted. Then this function OnLootUpdated is called only once. But if there are items in the list that should not be looted (e.g. trash or some configured not wanted items) the function is called multiple times, as many times as items were in the initial list. So if the initial list contained e.g. 5 items, with 2 unwanted ones, the function will be called 5 times.
I think that the removal of the wanted ones triggers a call of the event EVENT_LOOT_UPDATED again and the function is called again. When all items were looted in the first place the nect call of the function bails out as the loot list is empty.

I tried to unregister from the event at the beginning of the function and register at the end again, but with no luck.

Lua Code:
  1. self.control:UnregisterForEvent( EVENT_LOOT_UPDATED )
  2. ...
  3. self.control:RegisterForEvent(EVENT_LOOT_UPDATED, function( _, ... ) self:OnLootUpdated( ... )  end)
Is there a way to stop the event from firing, while I process the loot list ?

Many thanks for any suggestion

Askedal
  Reply With Quote
10/21/21, 08:29 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
>I think that the removal of the wanted ones triggers a call of the event EVENT_LOOT_UPDATED again and the function is called again.
You are easily able to find this out by adding a d("EVENT_LOOT_UPDATED") into your callback function

Lua Code:
  1. self.control:RegisterForEvent(EVENT_LOOT_UPDATED, function( _, ... )
  2.    d("-->EVENT_LOOT_UPDATED was called")
  3.    self:OnLootUpdated( ... )  
  4. end)

So you will see in chat how often, and when, it will be called.
I guess it will be called once per update to the loot window which might happen as you remove lines in there, yes. Or maybe even changing the position will call the event for the EVENT_LOOT_UPDATED. Depends on how ZOs implemented this.
maybe another event like EVENT_LOOT_RECEIVED could help here instead, you would have to try though.

If you do not want to let the event callback function self:OnLootUpdated( ... ) run multiple times try to surround it with a blocking/"already currently running" variable like this:


Lua Code:
  1. local lootInProgress = false
  2. self.control:RegisterForEvent(EVENT_LOOT_UPDATED, function( _, ... )
  3.    d("-->EVENT_LOOT_UPDATED was called")
  4.    if lootInProgress then return end
  5.    lootInProgress = true
  6.    self:OnLootUpdated( ... )  
  7.    lootInProgress = false
  8. end)

Should work the same with the unregister of the event, yes.
If this does not work there is something else triggering the code, maybe not via EVENT_LOOT_UPDATED?
Did you check if anything else in the addon calls self:OnLootUpdated function ?
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Performance Problem with EVENT_LOOT_UPDATED

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