Quote from FarmbuyerYeah, I had some misgivings about recommending this route when I pasted that code.
This is the kind of thing that I personally prefer. The code is essentially self-correcting in the face of changes. For example, if Blizzard announces to make the game more accessible to the Facebook image-meme generation, the labels "food and drink" will all be replaced by "noms" then your code won't need any changes. You'll still be getting a known-to-be-good string extracted from your base item, and comparing against that string in the wild. Same if Blizzard releases a game client localized for a new language.
The only hitch is that GetItemInfo will return nils for items which aren't in the client's local cache. Basically, as long as your base food has been seen by any of the player's toons previously in this game session, or is in the bags/bank of the first toon to log in, then the item will be in the cache.
The chances of that happening may be slim, so you might have to have a list of several "known to be food" item IDs, and GetItemInfo on all of them. This certainly isn't the only way to handle this situation, it's just a starting point for thinking.
Another thing you might do is, once you've extracted the string to use for comparisons, store it in your SavedVariables along with the current client locale. For future logins, you continue doing the scan-and-extract thing (because the strings might have changed for some locale), but even if GetItemInfo returns nil for everything, you can still fall back on a previously extracted string as "this is better than nothing".
Hm, that's really unfortunate. That could work too, but what about if I use the functions such as :
GetAuctionItemSubClasses() -- http://wowprogramming.com/docs/api/GetAuctionItemSubClasses
To get and store the proper current localized strings table, and then keep a premade set of variables with the indexes for the types, so for instance:
function CoreLoot:OnInitialize() CoreLoot.ItemSubtypes = GetAuctionItemSubClasses(4) -- assuming 4 is consumable end
Then to check:
if subclass == CoreLoot.ItemSubtypes[CoreLoot.ItemSubtypeIds.FoodAndDrink] ...
It's a bit verbose, and I'm not sure how much that subclass/class table will change, but if they don't then that could be fairly reliable (unless they too are based on having seen something this session)