Quantcast WoWInterface - View Single Post - Detect mail from ah
View Single Post
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