Thread Tools Display Modes
05/29/14, 09:21 PM   #1
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 655
Help with Complex Array.

Help with Complex Array.

Localization/HarvestMapData-en.lua
Localization/HarvestMapData-de.lua
Localization/HarvestMapData-fr.lua

I have three files in my manifest file listed like this. I have them that way to I can use a diff program like BeyoneCompare to line up the names so they are always in the exact sequence.


Lua Code:
  1. Harvest.langs = { "en", "de", "fr", }
  2. Harvest.DataStore = {
  3.    ["alikr"] = {},      --Alik'r Desert
  4.    ["auridon"] = {},    --Auridon, Khenarthi's Roost
  5.    ["bangkorai"] = {},  --Bangkorai
  6.    ["coldharbor"] = {}, --Coldharbour
  7.    ["cyrodiil"] = {},   --Cyrodiil
  8.    ["deshaan"] = {},    --"Deshaan"
  9.    ["eastmarch"] = {},  --Eastmarch
  10.    ["glenumbra"] = {},  --Glenumbra, Betnikh, Stros M'Kai
  11.    ["grahtwood"] = {},  --Grahtwood
  12.    ["greenshade"] = {}, --Greenshade
  13.    ["malabaltor"] = {}, --Malabal Tor
  14.    ["reapersmarch"] = {},  --Reaper's March
  15.    ["rivenspire"] = {}, --Rivenspire
  16.    ["shadowfen"] = {},  --Shadowfen
  17.    ["stonefalls"] = {}, --Stonefalls, Bal Foyen, Bleakrock Isle
  18.    ["stormhaven"] = {}, --Stormhaven
  19.    ["therift"] = {},    --The Rift
  20.    ["craglorn"] = {},    --Craglorn
  21. }
This is the beginning of my complex array. I am using code with permission from Undiscovered but I want to change it.
Lua Code:
  1. Harvest.DataStore["en"]["alikr"] = {
  2. --Alik'r Desert (Daggerfall, lvl 31-37)
  3.    ["alikr_base"] = {            --Alik'r Desert
  4.       --en
  5.       { "Aldunz", 3 },
  6. }
Then for the next part I want to define it that way. So that I can change the first part in the array to this.
Lua Code:
  1. Harvest.DataStore = {
  2.     ["alikr"] = Harvest.DataStore[Harvest.langs]["alikr"],
  3.     ........
  4. }
How can I structure it better? I want it to be something I could do a For loop on like this

Lua Code:
  1. for zone, zones in pairs(Harvest.DataStore) do
  2.     for lang, langs in pairs(zones) do
  3.         for subzone, subzones in pairs(langs) do
  4.             for map, maps in pairs(subzones) do
  5.                 d("Zone : " .. zone .. " : lang : " .. lang .. " : subzone : " .. subzone .. " : map : " .. map)
would return this

Zone : alikr : lang : en : subzone : alikr_base : map : Aldunz

Lua Code:
  1. Harvest.DataStore["alikr"]["en"]["alikr_base"] = {            --Alik'r Desert
  2.       --en
  3.       { "Aldunz", 3 },
  4. }
How can I accomplish that result, I fear I am doing something terribly wrong.

Lua Code:
  1. Harvest.DataStore["en"]["alikr_base"] = {
  2.     --Alik'r Desert (Daggerfall, lvl 31-37)
  3.     --Alik'r Desert
  4.       --en
  5.       { "Aldunz", 3 },
  6. }
  7.  
  8. Harvest.DataStore = {
  9.    ["alikr"] = {Harvest.DataStore["en"]["alikr_base"],
  10.                 Harvest.DataStore["de"]["alikr_base"],
  11.                 Harvest.DataStore["fr"]["alikr_base"]}  --Alik'r Desert
Something like that maybe?

EDIT: Nope none of my variations are working.

Last edited by Sharlikran : 05/29/14 at 10:42 PM.
  Reply With Quote
05/29/14, 11:44 PM   #2
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   #3
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   #4
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   #5
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 655
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   #6
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   #7
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 655
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   #8
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 655
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, 03:21 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. 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

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