ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Converting Destinations from LAM-1.0 to LAM-2.0 (https://www.esoui.com/forums/showthread.php?t=2447)

SnowmanDK 11/18/14 12:30 PM

Converting Bank Manager Revived from LAM-1.0 to LAM-2.0
 
I am puzzled about a problem I have.

The code using LAM-1.0 is this:
Lua Code:
  1. for k,craftKey in pairs(blackSmithingRules) do
  2.         lam:AddDropdown(panelID, craftKey.."#"..numProfile, getTranslated(craftKey), "", getTranslateTable(sendingType),
  3.         function() return getTranslated(BankManager.Saved[craftKey][numProfile]) end,
  4.         function(val) changeTranslateTable(val,craftKey,numProfile) end)
  5.     end
I was hoping to convert it to 2.0 like this:
Lua Code:
  1. for k, craftKey in pairs(blackSmithingRules) do
  2.         {--[17.x]
  3.             type = "dropdown",
  4.             name = getTranslated(craftKey),
  5.             choices = getTranslateTable(sendingType),
  6.             getFunc = function() return getTranslated(BankManager.Saved[craftKey][numProfile]) end,
  7.             setFunc = function(value) changeTranslateTable(value,craftKey,numProfile) end,
  8.         },
  9.     end
Sadly I get an error saying: unexpected symbol near 'for'.

Any idea how I can fix this?

Sasky 11/18/14 12:50 PM

Looping over the block does nothing. You'd need to build-up a table by appending each entry from the loop:

Lua Code:
  1. local settingsTable = {}
  2. for k, craftKey in pairs(blackSmithingRules) do
  3.     local entry = {--[17.x]
  4.         type = "dropdown",
  5.         name = getTranslated(craftKey),
  6.         choices = getTranslateTable(sendingType),
  7.         getFunc = function() return getTranslated(BankManager.Saved[craftKey][numProfile]) end,
  8.         setFunc = function(value) changeTranslateTable(value,craftKey,numProfile) end,
  9.     }
  10.     table.append(settingsTable, entry);
  11. end
Keep in mind that ordering matters in the options table. You can either table.append everything to build it up, or just make the table in the normal manner up to that point then use table.append from then on.

Alternatively, if you want to stick to the function-based style (rather than make the table yourself), you can take a look at:
http://www.esoui.com/downloads/info5...Interface.html
You'd have to extend it for any of the new LAM2 features (like texture), but it is something to consider.

SnowmanDK 11/18/14 01:08 PM

Quote:

Originally Posted by Sasky (Post 13324)
Looping over the block does nothing. You'd need to build-up a table by appending each entry from the loop:

Lua Code:
  1. local settingsTable = {}
  2. for k, craftKey in pairs(blackSmithingRules) do
  3.     local entry = {--[17.x]
  4.         type = "dropdown",
  5.         name = getTranslated(craftKey),
  6.         choices = getTranslateTable(sendingType),
  7.         getFunc = function() return getTranslated(BankManager.Saved[craftKey][numProfile]) end,
  8.         setFunc = function(value) changeTranslateTable(value,craftKey,numProfile) end,
  9.     }
  10.     table.append(settingsTable, entry);
  11. end
Keep in mind that ordering matters in the options table. You can either table.append everything to build it up, or just make the table in the normal manner up to that point then use table.append from then on.

Alternatively, if you want to stick to the function-based style (rather than make the table yourself), you can take a look at:
http://www.esoui.com/downloads/info5...Interface.html
You'd have to extend it for any of the new LAM2 features (like texture), but it is something to consider.

I tried using your code, but gets the same error in the "for" line as before.
Guess I am gonna do it the hard way, by adding them one by one instead.
I already converted most of the settings menu, but thanks for the input :)

SnowmanDK 11/18/14 01:38 PM

lol don't know why I wrote "Destinations" in topic.
It IS Bank Manager Revived I am working on at the moment.

merlight 11/18/14 02:20 PM

Quote:

Originally Posted by SnowmanDK (Post 13323)
Sadly I get an error saying: unexpected symbol near 'for'.

That likely means you have something evil before the for. When I simply pasted the piece from your initial post into Lua console, I got unexpected symbol near '{' (which was kind of expected :D)

edit: probably some unclosed braces...

Sasky 11/18/14 03:24 PM

Ah yeah. If you're trying to do something along these lines it'd throw the error at the for statement because you can't have a for statement within a table.
Lua Code:
  1. --BAD STRUCTURE. DO NOT USE
  2. local addonControls = {
  3.     --controls here
  4.    
  5.    --BAD STRUCTURE
  6.    for( .... ) do
  7.       {
  8.           --Data here
  9.       }
  10.    end
  11. }

Might go ahead and throw the full function/file on pastebin or something so can better see what the error is.

SnowmanDK 11/18/14 03:48 PM

Quote:

Originally Posted by merlight (Post 13327)
That likely means you have something evil before the for. When I simply pasted the piece from your initial post into Lua console, I got unexpected symbol near '{' (which was kind of expected :D)

edit: probably some unclosed braces...

Well if I comment out that entire "for" loop then I get no errors at all, so it is in that loop it goes wrong.
I can see Sasky pointed the problem out ;)
Quote:

Originally Posted by Sasky (Post 13329)
...you can't have a for statement within a table.

On with the job the oldfashion way, I guess :)

Garkin 11/18/14 06:15 PM

Check how it is done in HarvestMap addon.
Lua Code:
  1. local optionsTable = setmetatable({}, { __index = table })
  2.  
  3. optionsTable:insert({
  4.     type = "button",
  5.     name = "Import other Accounts",
  6.     tooltip = "Moves gathered data from other Accounts to this one. This can also restore lost data after an ESO update.",
  7.     warning = "Please create a backup of your data first! Copy the file SavedVariables/HarvestMap.lua to somwhere else.",
  8.     width = "half",
  9.     func = function()
  10.         Harvest.makeGlobal("nodes")
  11.     end
  12. })
  13. --lots of other entries
  14.  
  15. --entries added by for loop
  16. for profession = 1, 8 do
  17.     optionsTable:insert({
  18.         type = "header",
  19.         name = Harvest.localization[ "filter"..profession ] .. " pin Options",
  20.     })
  21.     CreateFilter( profession )
  22.     CreateImportFilter( profession )
  23.     CreateGatherFilter( profession )
  24.     CreateSizeSlider( profession )
  25.     CreateColorPicker( profession )
  26. end
  27.  
  28. --rest of the entries

SnowmanDK 11/18/14 07:39 PM

Quote:

Originally Posted by Garkin (Post 13331)
Check how it is done in HarvestMap addon.
Lua Code:
  1. local optionsTable = setmetatable({}, { __index = table })
  2.  
  3. optionsTable:insert({
  4.     type = "button",
  5.     name = "Import other Accounts",
  6.     tooltip = "Moves gathered data from other Accounts to this one. This can also restore lost data after an ESO update.",
  7.     warning = "Please create a backup of your data first! Copy the file SavedVariables/HarvestMap.lua to somwhere else.",
  8.     width = "half",
  9.     func = function()
  10.         Harvest.makeGlobal("nodes")
  11.     end
  12. })
  13. --lots of other entries
  14.  
  15. --entries added by for loop
  16. for profession = 1, 8 do
  17.     optionsTable:insert({
  18.         type = "header",
  19.         name = Harvest.localization[ "filter"..profession ] .. " pin Options",
  20.     })
  21.     CreateFilter( profession )
  22.     CreateImportFilter( profession )
  23.     CreateGatherFilter( profession )
  24.     CreateSizeSlider( profession )
  25.     CreateColorPicker( profession )
  26. end
  27.  
  28. --rest of the entries

I have converted what I had done previously, and it works with your setup :)

I am seriously scratching my head over this, though, as I can't figure out how to convert it to a format that will be accepted:
Lua Code:
  1. for k, craftKey in pairs(blackSmithingRules) do
blackSmithingRules looks like this:
Lua Code:
  1. blackSmithingRules = {
  2.     "ITEMTYPE_BLACKSMITHING_BOOSTER",
  3.     "ITEMTYPE_BLACKSMITHING_MATERIAL",
  4.     "ITEMTYPE_BLACKSMITHING_RAW_MATERIAL"
  5. }

Garkin 11/18/14 09:51 PM

Your original code modified to use table.insert (I assume that your table with options is called "optionsTable"):
Lua Code:
  1. for _, craftKey in pairs(blackSmithingRules) do
  2.     table.insert(optionsTable, {
  3.         type = "dropdown",
  4.         name = getTranslated(craftKey),
  5.         choices = getTranslateTable(sendingType),
  6.         getFunc = function() return getTranslated(BankManager.Saved[craftKey][numProfile]) end,
  7.         setFunc = function(value) changeTranslateTable(value,craftKey,numProfile) end,
  8.     })
  9. end
This code is basically the same as was suggested by Sasky.

Modified code if you use metatable as it is in HarvestMaps addon (again, I assume that you use "optionsTable"):
Lua Code:
  1. for _, craftKey in pairs(blackSmithingRules) do
  2.     optionsTable:insert({
  3.         type = "dropdown",
  4.         name = getTranslated(craftKey),
  5.         choices = getTranslateTable(sendingType),
  6.         getFunc = function() return getTranslated(BankManager.Saved[craftKey][numProfile]) end,
  7.         setFunc = function(val) changeTranslateTable(val, craftKey, numProfile) end,
  8.     })
  9. end

SnowmanDK 11/19/14 11:38 AM

Quote:

Originally Posted by Garkin (Post 13335)
Modified code if you use metatable as it is in HarvestMaps addon (again, I assume that you use "optionsTable"):
Lua Code:
  1. for _, craftKey in pairs(blackSmithingRules) do
  2.     optionsTable:insert({
  3.         type = "dropdown",
  4.         name = getTranslated(craftKey),
  5.         choices = getTranslateTable(sendingType),
  6.         getFunc = function() return getTranslated(BankManager.Saved[craftKey][numProfile]) end,
  7.         setFunc = function(val) changeTranslateTable(val, craftKey, numProfile) end,
  8.     })
  9. end

I used HarvestMap as template yes, and my table is called "optionsTable".
This part works fine with no issues:
Lua Code:
  1. optionsTable:insert({ --[16] --> Stacks Rules submenu <--
  2.         type = "submenu",
  3.         name = getTranslated("subMenuStacksRules"),
  4.         tooltip = getTranslated("subMenuStacksRulesTooltip"),
  5.         controls = {
  6.             {--[16.1]
  7.                 type = "dropdown",
  8.                 name = getTranslated("fillStacks"),
  9.                 tooltip = getTranslated("fillStacksTooltip"),
  10.                 choices = getTranslateTable(sendingType),
  11.                 getFunc = function() return getTranslated(BankManager.Saved["fillStacks"][numProfile]) end,
  12.                 setFunc = function(value) changeTranslateTable(value,"fillStacks",numProfile) end,
  13.             },
  14.             {--[16.2]
  15.                 type = "checkbox",
  16.                 name = getTranslated("stackSizeCheckBox"),
  17.                 tooltip = getTranslated("stackSizeCheckBoxTooltip"),
  18.                 getFunc = function() return BankManager.Saved["stackSizeCheckBox"][numProfile] end,
  19.                 setFunc = function(value) BankManager.Saved["stackSizeCheckBox"][numProfile] = value end,
  20.             },
  21.             {--[16.3]
  22.                 type = "slider",
  23.                 name = getTranslated("stackSizeSlider"),
  24.                     tooltip = getTranslated("stackSizeSliderTooltip"),
  25.                 min = 1,
  26.                     max = 100,
  27.                 step = 1,
  28.                 getFunc = function() return BankManager.Saved["stackSizeSlider"][numProfile] end,
  29.                 setFunc = function(value) BankManager.Saved["stackSizeSlider"][numProfile] = value end,
  30.             },
  31.         },
  32.     })
This one fails:
Lua Code:
  1. optionsTable:insert({ --[17] --> Blacksmithing Rules submenu <--
  2.         type = "submenu",
  3.         name = getTranslated("CRAFTING_TYPE_BLACKSMITHING"),
  4.         controls = {
  5.             {--[17.1]
  6.                     type = "dropdown",
  7.                 name = getTranslated("setAllOptions") .."|r",
  8.                 tooltip = getTranslated("setAllOptionsTooltip"),
  9.                 choices = getTranslateTable(sendingType),
  10.                 getFunc = function() return "-" end,
  11.                 setFunc = function(value) setAllOptions(value,numProfile,blackSmithingRules) end,
  12.             },
  13.             for _, craftKey in pairs(blackSmithingRules) do  --<-- LINE 351
  14.                 optionsTable:insert({
  15.                     type = "dropdown",
  16.                     name = getTranslated(craftKey),
  17.                     choices = getTranslateTable(sendingType),
  18.                     getFunc = function() return getTranslated(BankManager.Saved[craftKey][numProfile]) end,
  19.                     setFunc = function(val) changeTranslateTable(val, craftKey, numProfile) end,
  20.                 })
  21.             end
  22.         },
  23.     })
with this error:
Code:

user:/AddOns/BankManagerRevived/UI/BankManagerOpts.lua:351: unexpected symbol near 'for'
Line 351 is line 13 in this cutout. I just don't get it :confused:

merlight 11/19/14 12:26 PM

You're still failing to understand the basic fact that you cannot put a for loop (or any other non-expression statement, for that matter), into table definition (or any other place where an expression is expected, for that matter).

Lua Code:
  1. optionsTable:insert({ --[17] --> Blacksmithing Rules submenu <--
  2.         type = "submenu",
  3.         name = getTranslated("CRAFTING_TYPE_BLACKSMITHING"),
  4.         controls = {
  5.             {--[17.1]
  6.                     type = "dropdown",
  7.                 name = getTranslated("setAllOptions") .."|r",
  8.                 tooltip = getTranslated("setAllOptionsTooltip"),
  9.                 choices = getTranslateTable(sendingType),
  10.                 getFunc = function() return "-" end,
  11.                 setFunc = function(value) setAllOptions(value,numProfile,blackSmithingRules) end,
  12.             },
  13.         },
  14.     })
  15.             for _, craftKey in pairs(blackSmithingRules) do
  16.                 optionsTable:insert({
  17.                     type = "dropdown",
  18.                     name = getTranslated(craftKey),
  19.                     choices = getTranslateTable(sendingType),
  20.                     getFunc = function() return getTranslated(BankManager.Saved[craftKey][numProfile]) end,
  21.                     setFunc = function(val) changeTranslateTable(val, craftKey, numProfile) end,
  22.                 })
  23.             end

SnowmanDK 11/19/14 01:12 PM

Quote:

Originally Posted by merlight (Post 13346)
You're still failing to understand the basic fact that you cannot put a for loop (or any other non-expression statement, for that matter), into table definition (or any other place where an expression is expected, for that matter).

Lua Code:
  1. optionsTable:insert({ --[17] --> Blacksmithing Rules submenu <--
  2.         type = "submenu",
  3.         name = getTranslated("CRAFTING_TYPE_BLACKSMITHING"),
  4.         controls = {
  5.             {--[17.1]
  6.                     type = "dropdown",
  7.                 name = getTranslated("setAllOptions") .."|r",
  8.                 tooltip = getTranslated("setAllOptionsTooltip"),
  9.                 choices = getTranslateTable(sendingType),
  10.                 getFunc = function() return "-" end,
  11.                 setFunc = function(value) setAllOptions(value,numProfile,blackSmithingRules) end,
  12.             },
  13.         },
  14.     })
  15.             for _, craftKey in pairs(blackSmithingRules) do
  16.                 optionsTable:insert({
  17.                     type = "dropdown",
  18.                     name = getTranslated(craftKey),
  19.                     choices = getTranslateTable(sendingType),
  20.                     getFunc = function() return getTranslated(BankManager.Saved[craftKey][numProfile]) end,
  21.                     setFunc = function(val) changeTranslateTable(val, craftKey, numProfile) end,
  22.                 })
  23.             end

But it works in HarvestMap!?!? That just makes me understand even less :confused:
EDIT: you mean I have to move the loop into a function of its own and call that?

merlight 11/19/14 03:15 PM

Read carefully. You have to move the for loop out of the table constructor. What works in HarvestMap is valid Lua code, yours isn't.

Sasky showed you what's wrong with your code, Garkin gave you a prefectly valid example, yet you still keep that loop in the table. Just paste what I posted above, with no crap around it. I didn't bother to fix indentation, but the braces are fixed.

Garkin 11/19/14 03:16 PM

You can't use for loop in the table definition. You have to close table definition first and then add items to that table.
Lua Code:
  1. optionsTable:insert({ --[17] --> Blacksmithing Rules submenu <--
  2.     type = "submenu",
  3.     name = getTranslated("CRAFTING_TYPE_BLACKSMITHING"),
  4.     controls = setmetatable({}, { __index = table })
  5. })
  6.  
  7. --get reference to the controls table of the last added item (submenu)
  8. local submenuControls = optionsTable[#optionsTable].controls
  9.  
  10. submenuControls:insert({--[17.1]
  11.     type = "dropdown",
  12.     name = getTranslated("setAllOptions") .."|r",
  13.     tooltip = getTranslated("setAllOptionsTooltip"),
  14.     choices = getTranslateTable(sendingType),
  15.     getFunc = function() return "-" end,
  16.     setFunc = function(value) setAllOptions(value,numProfile,blackSmithingRules) end,
  17. })
  18.  
  19. for _, craftKey in pairs(blackSmithingRules) do  --<-- LINE 351
  20.     submenuControls:insert({
  21.         type = "dropdown",
  22.         name = getTranslated(craftKey),
  23.         choices = getTranslateTable(sendingType),
  24.         getFunc = function() return getTranslated(BankManager.Saved[craftKey][numProfile]) end,
  25.         setFunc = function(val) changeTranslateTable(val, craftKey, numProfile) end,
  26.     })
  27. end

SnowmanDK 11/19/14 04:13 PM

FINALLY I got it. Thank you guys for all the help :banana:
Sorry for being so thickheaded that I didn't understand what you tried to explain earlier.


All times are GMT -6. The time now is 05:55 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI