View Single Post
05/30/14, 03:21 AM   #11
Wobin
 
Wobin's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 78
Originally Posted by Sharlikran View Post
Lua Code:
  1. function Harvest.IsValidWoodworkingName(name)
  2.     for lang, langs in pairs(Harvest.langs) do
  3.         for k, v in pairs(Harvest.woodworking[langs]) do
  4.             if v == name then
  5.                 return true
  6.             end
  7.         end
  8.     end
  9.  
  10.     return false
  11. end
Like that you mean?
Yes. That way, if there's a match, it doesn't bother checking the rest of the tables.

As for your requirements, there are two ways you can go about it, depending on how often the information is requested.

If the requests are relatively scarce, you can do as you do above, and just create functions that loop through the tables, til you find a match, then create a chunk of info for your use.

If you need more speed, ie, your requests are very very often, you can create lookup tables in memory so that when you reference MapName["Aldunz"] it'll return { [Zone] : "alikr", [lang] : "en", [subzone] : "alikr_base", [map] : "Aldunz"}. This will frontload the work, by doing it all at load, but will speed up lookup. You just need to know what information you're using, and what format you need the result in.

I advise you read up on how Lua handles tables and references first though, so you understand just what sort of structures you're creating.
  Reply With Quote