Thread Tools Display Modes
05/29/14, 11:44 PM   #1
Vuelhering
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 169
I don't have an answer for you, but after glancing through this, my brain is screaming "anonymous closure".

Not sure that will do anything, though

Lua is odd, but this code just bothers me at a gut level.
Code:
Harvest.DataStore = {
        ["alikr"] = Harvest.DataStore[Harvest.langs]["alikr"],
        ........
}
  Reply With Quote
05/30/14, 12:36 AM   #2
Wobin
 
Wobin's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 78
Originally Posted by Vuelhering View Post
I don't have an answer for you, but after glancing through this, my brain is screaming "anonymous closure".

Not sure that will do anything, though

Lua is odd, but this code just bothers me at a gut level.
Code:
Harvest.DataStore = {
        ["alikr"] = Harvest.DataStore[Harvest.langs]["alikr"],
        ........
}
It's storing a table reference at that point. Not sure if that'll actually work as a SV result (if that's what it is).
  Reply With Quote
05/30/14, 12:39 AM   #3
Wobin
 
Wobin's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 78
The answer to 'how do I store this info' will largely rest on the question "What are you doing with the info?"

Note that you can store the information as sparsely as you need for storage purposes, and recombine them in game for speed of reference and create lookup tables and the like.
  Reply With Quote
05/30/14, 12:43 AM   #4
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 674
I am going to try this Lua console from source forge, no idea how to use it yet though. ^_^

Does anyone know a good Lua console that is easy to run like Python and Ruby?

Lua Code:
  1. Harvest.langs = { "en", "de", "fr", }
  2.  
  3. Harvest.woodworking = {
  4.     ["en"] = {
  5.         "Ashtree",
  6.         "Beech",
  7.         "Birch",
  8.         "Hickory",
  9.         "Mahogany",
  10.         "Maple",
  11.         "Nightwood",
  12.         "Oak",
  13.         "Yew",
  14.     },
  15.     ["de"] = {
  16.         "Eschenholz",
  17.         "Buche", -- "Buchenholz"
  18.         "Birkenholz",
  19.         "Hickoryholz",
  20.         "Mahagoniholz",
  21.         "Ahornholz",
  22.         "Nachtholz",
  23.         "Eiche",
  24.         "Eibenholz",
  25.     },
  26.     ["fr"] = {
  27.         "Frêne",
  28.         "Hêtre",
  29.         "Bouleau",
  30.         "Hickory",
  31.         "Acajou",
  32.         "Érable",
  33.         "Bois de nuit",
  34.         "Chêne",
  35.         "If",
  36.     },
  37. }
  38.  
  39. function Harvest.IsValidWoodworkingName(name)
  40.     local nameMatch = false
  41.     for lang, langs in pairs(Harvest.langs) do
  42.         for k, v in pairs(Harvest.woodworking[langs]) do
  43.             if v == name then
  44.                 nameMatch = true
  45.             end
  46.         end
  47.     end
  48.  
  49.     return nameMatch
  50. end

That all works fine, so I have to build off of it and try to apply it to what I want with the map names.
  Reply With Quote
05/30/14, 01:07 AM   #5
Wobin
 
Wobin's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 78
Originally Posted by Sharlikran View Post
I am going to try this Lua console from source forge, no idea how to use it yet though. ^_^

Does anyone know a good Lua console that is easy to run like Python and Ruby?

Lua Code:
  1. function Harvest.IsValidWoodworkingName(name)
  2.     local nameMatch = false
  3.     for lang, langs in pairs(Harvest.langs) do
  4.         for k, v in pairs(Harvest.woodworking[langs]) do
  5.             if v == name then
  6.                 nameMatch = true
  7.             end
  8.         end
  9.     end
  10.  
  11.     return nameMatch
  12. end

That all works fine, so I have to build off of it and try to apply it to what I want with the map names.
Just as a note, you can escape early from that loop by using return true as soon as you have a match and return false outside the loop.
  Reply With Quote
05/30/14, 01:38 AM   #6
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 674
Originally Posted by Wobin View Post
Just as a note, you can escape early from that loop by using return true as soon as you have a match and return false outside the loop.
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?
  Reply With Quote
05/30/14, 01:40 AM   #7
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 674
Warning: Spoiler

If you click the spoiler, as you can see I need to make it modular or I'll end up with a wall of text. Each map file is already over 1200 lines long.

Originally Posted by Wobin View Post
The answer to 'how do I store this info' will largely rest on the question "What are you doing with the info?"

Note that you can store the information as sparsely as you need for storage purposes, and recombine them in game for speed of reference and create lookup tables and the like.
Two things 1) I want to pass the map name, "cahute de Cadwell^fd" as an argument to a function and return the zone, subzone, and an index number. Then use string.format to end up with "coldharbor/coldharbour_base". The index would be that it was the 5th map name in the array. 2) Pass the zone, subzone, and the index and get the map name of any of the three languages thus ending up with a way to translate "cahute de Cadwell^fd" to "Cadwell's Hovel".

Last edited by Sharlikran : 05/30/14 at 01:58 AM.
  Reply With Quote
05/30/14, 02:00 AM   #8
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 674
Lua Code:
  1. Harvest.DataStore_en_auridon_base
  2. Harvest.DataStore.en.auridon.base
Ok I am confused. What is the difference between the two lines. ESO told me I was trying to access a nil value with the line that has the dots in it. Do this dots make Lua think it's a function? The other line works.
  Reply With Quote
05/30/14, 03:10 AM   #9
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. Harvest.DataStore_en_auridon_base
  2. Harvest.DataStore.en.auridon.base
Ok I am confused. What is the difference between the two lines. ESO told me I was trying to access a nil value with the line that has the dots in it. Do this dots make Lua think it's a function? The other line works.
The second are table references, the first is a single variable.

Essentially:

Code:
Harvest.DataStore.en.auridon.base
is
Code:
Harvest = {}
Harvest["DataStore"] = {}
Harvest["DataStore"]["en"] = {}
Harvest["DataStore"]["en"]["auridon"] = {}
Harvest["DataStore"]["en"]["auridon"]["base"] = {}
Code:
Harvest.DataStore_en_auridon_base
is
Code:
Harvest = {}
Harvest["DataStore_en_auridon_base"] = {}
You have to create the table before you can add further items to it otherwise you'll get a nil reference.

I suggest you read up on Lua, PiL is a good resource to learn the syntax of Lua
  Reply With Quote
05/30/14, 03:21 AM   #10
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
05/30/14, 07:21 AM   #11
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 674
Originally Posted by Wobin View Post
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.
That is good advice. Since you probably know more then I, does this page seem to you like it would explain it well enough? Do you think it's missing what you were trying to explain about a "lookup tables"? What do you think? I wont need to remove, insert, or sort the table because it will remain constant.

Last edited by Sharlikran : 05/30/14 at 08:24 AM.
  Reply With Quote
05/30/14, 07:47 AM   #12
Halja
 
Halja's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 111
Originally Posted by Sharlikran View Post
That is good advice. Since you probably know more then I, does this page seem to you like it would explain it well enough? Do you think it's missing what you were trying to explain about a "lookup tables"? What do you think? I wont need to remove, insert, or sort the table because it will remain constant.
Unless I'm not completely reading this thread, you can vastly simplify your code by only loading the language file(s) the client has currently running. You do this in your manifest by using the $(language) variable. At run-time the launcher will pick. That way you are also using less memory, your search index can be in your native language, and the code does not need all the if else on language anymore. The value will be the expected text based on the language.

Instead of three line in the manifest like
Code:
Localization/HarvestMapData-en.lua
Localization/HarvestMapData-de.lua
Localization/HarvestMapData-fr.lua
It would be:
Code:
Localization/HarvestMapData-$(language).lua
Based on what the cVar("Language.2") hold, one of your three originally files will be loaded. This is how ZOS is doing the localization for the most part on strings.
Hope this help,
--halja
  Reply With Quote
05/30/14, 08:19 AM   #13
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Metatables

I understand that you want to store references from three different tables into the single table. If you use unique keys, it can be done using metatables. If you use just indexes (they are not unique), it will be much more complicated.

I don't know if it is exactly what you want, but I think it's worth of trying.
Lua Code:
  1. Harvest.DataStore["en"]["alikr_base"] = {
  2.    ["Aldunz"] = 3,
  3.     .........
  4. }
  5. Harvest.DataStore["de"]["alikr_base"] = {
  6.    ["Aldunz^N,in"] = 3,
  7.     .........
  8. }
  9. Harvest.DataStore["fr"]["alikr_base"] = {
  10.    ["Aldunz^M"] = 3,
  11.     .........
  12. }
  13.  
  14. Harvest.DataStore["alikr"]["alikr_base"] = {}
  15.  
  16. setmetatable(Harvest.DataStore["de"]["alikr_base"], { __index = Harvest.DataStore["fr"]["alikr_base"] })
  17. setmetatable(Harvest.DataStore["en"]["alikr_base"], { __index = Harvest.DataStore["de"]["alikr_base"] })
  18. setmetatable(Harvest.DataStore["alikr"]["alikr_base"], { __index = Harvest.DataStore["en"]["alikr_base"] })

Metatables:
http://nova-fusion.com/2011/06/30/lu...bles-tutorial/
http://lua-users.org/wiki/MetatableEvents
http://lua-users.org/wiki/MetamethodsTutorial
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Help with Complex Array.


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