Thread Tools Display Modes
04/25/14, 03:16 PM   #1
Teli
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 19
waiting for event to trigger

I'm working on an addon that delete unwanted mail items. The problem I'm having is if I loop through the MailIds to call DeleteMail(MailId) it will delete the first one and then it won't delete the rest. The issue seems to be because the server needs to act on the first one before it can act on the rest. I can queue up other items to be deleted in by adding them to the EVENT_MAIL_REMOVED event. I'm wondering what is the best way to pause the function or wait until there is a response back from the server or time out.?
  Reply With Quote
04/25/14, 03:57 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
The best way is to listen for the appropriate events.
  Reply With Quote
04/25/14, 04:58 PM   #3
Teli
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 19
Originally Posted by Seerah View Post
The best way is to listen for the appropriate events.
I'm doing that with an event handler but the problem is how do I get the delete another item only after the even has fired. there is a delay in when I call the event. So if I have
Lua Code:
  1. for k1, v1 in pairs(mailInfo) do
  2.   d(delComplete)
  3.    if delComplete then DeleteMail(v1.mailId,false) end
  4.    delComplete = false --mark it as false only the event can mark it as true
  5. end
and an event handler
Lua Code:
  1. delComplete = true
  2. function mailOpen.MailRemoved(eventCode, mailId)
  3.    delComplete = true -- mark it true from event code
  4.    d('mail removed')
  5. end

It'll delete the first item and it won't delete the rest. I tried it like this. and get the same thing.

Lua Code:
  1. for k1, v1 in pairs(mailInfo) do
  2.    DeleteMail(v1.mailId,false)
  3. end

The chat window displays

Code:
true
false
false
false
false
false
mail removed
So the problem seems to be it runs through all the addon code first
  Reply With Quote
04/25/14, 05:55 PM   #4
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Easiest would be to do most of the work in the MAIL_REMOVED event.

When you want to start the mail delete action:
You store the mail info you want to delete in an array and a counter as index where you are.
Then you delete the first mail only.

The MAIL_REMOVED event increases the counter and just deletes the one mail the counter points at.
It stops deleting the mail, when the counter is higher than the count of items in the array.


This way your delete action automatically gets triggered once the previous one is finished, as it is done by the MAIL_REMOVED event.

Last edited by Iyanga : 04/25/14 at 05:59 PM.
  Reply With Quote
04/25/14, 06:05 PM   #5
Teli
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 19
thanks for your help. I was already on the right path when I saw your response. Here's what I did

Lua Code:
  1. function mailOpen.QueueDelete(mailId,forceDelete)
  2.     table.insert(delQueue,{['mailId']=mailId,['forceDelete']=forceDelete})
  3. end
  4. function mailOpen.ProcessDelQueue()
  5.     if delQueue[1].mailId ~= nil then
  6.         DeleteMail(delQueue[1].mailId,delQueue[1].forceDelete)
  7.         table.remove(delQueue,1)
  8.     end
  9. end
  10.  
  11.  
  12. function mailOpen.Test()
  13.     for k, v in pairs(mailOpen.mailInfo) do
  14.             if v.unread then RequestReadMail(v.mailId) end
  15.             mailOpen.QueueDelete(v.mailId,false)
  16.     end
  17.     mailOpen.ProcessDelQueue()
  18. end
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » waiting for event to trigger

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