Quantcast Detect mail from ah - WoWInterface
 
Thread Tools Display Modes
09-22-14, 03:27 AM   #1
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 54
Detect mail from ah

Hello,

first my code:

Lua Code:
  1. function Accountant_DetectAhMail()
  2.     local numItems = GetInboxNumItems()
  3.     local invoiceType = GetInboxInvoiceInfo(numItems)
  4.     if invoiceType == "seller" then
  5.     auditorMode = "AH";
  6.         else
  7.     auditorMode = "MAIL";
  8.     end
  9. end

I'm trying to Detect if the mail is from a succesfull auction, it never return the AH or MAIL, i'm still new to lua stuff, been looking at
http://wowprogramming.com/docs/api/GetInboxInvoiceInfo
http://wowprogramming.com/docs/api/GetInboxNumItems
  Reply With Quote
09-22-14, 03:55 AM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
I don't know what the invoiceType string exactly looks like, but I guess it is something like "Sold item: Seller ..."?

In that case you'll have to search for the pattern "seller" inside the string. Comparing the full string does not work as "seller" is not equal to "Sold item: Seller ....".

Lua Code:
  1. if string.find(invoiceType, "seller") then

If you are unsure if it is "seller" or "Seller" or "SELLER" or whatever, then it could be helpful to convert invoiceType before comparing them:

Lua Code:
  1. if string.find(string.lower(invoiceType), "seller") then

And last but not least you should declare auditorMode as local and return it with you function:

Lua Code:
  1. function Accountant_DetectAhMail()
  2.     local numItems = GetInboxNumItems()
  3.     local invoiceType = GetInboxInvoiceInfo(numItems)
  4.     local auditorMode
  5.     if invoiceType == "seller" then
  6.         auditorMode = "AH";
  7.     else
  8.         auditorMode = "MAIL";
  9.     end
  10.     return auditorMode
  11. end

If you do not use auditorMode somewhere else then this would be a better way to do it:
Lua Code:
  1. function Accountant_DetectAhMail()
  2.     local numItems = GetInboxNumItems()
  3.     local invoiceType = GetInboxInvoiceInfo(numItems)
  4.     if invoiceType == "seller" then
  5.         return "AH"
  6.     else
  7.         return "MAIL"
  8.     end
  9. end

Personally I would return a boolean instead of a string as this is a bit easyer to handle. Like

Lua Code:
  1. function Accountant_DetectAhMail()
  2.     local numItems = GetInboxNumItems()
  3.     local invoiceType = GetInboxInvoiceInfo(numItems)
  4.     if invoiceType == "seller" then
  5.         return true
  6.     end
  7. end
Then use it like
Lua Code:
  1. if Accountant_DetectAhMail() then
  2.     --
  3. end
instead of doing something like
Lua Code:
  1. if Accountant_DetectAhMail() == "AH" then
  2.     --
  3. end

[e]
And if you're not using multiple files with you addon, then you should probably declare you function as local:
Lua Code:
  1. local function Accountant_DetectAhMail()
  2.     local numItems = GetInboxNumItems()
  3.     local invoiceType = GetInboxInvoiceInfo(numItems)
  4.     if invoiceType == "seller" then
  5.         return true
  6.     end
  7. end

Last edited by Duugu : 09-22-14 at 04:04 AM.
  Reply With Quote
09-22-14, 04:17 AM   #3
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 54
Very nice thanks for the help, gonna play a bit whit it
  Reply With Quote
09-23-14, 12:34 AM   #4
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 54
Still don't fire when i get money from the ah in the mail.
  Reply With Quote
09-23-14, 06:03 AM   #5
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
do'h ... just had overwritten my on old post

Last edited by Duugu : 09-23-14 at 07:22 AM.
  Reply With Quote
09-23-14, 07:06 AM   #6
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 54
Tested the last code you added, its never print any thing.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Detect mail from ah

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