Thread Tools Display Modes
11-02-18, 07:02 PM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Need a second set of eyes to spot the error

I am getting an "unexpected symbol near 'local'" error, and for the life of me, I can't see the thing. Is the word "list" a bad name for a variable in Lua and I missed the memo?

Full error:
Lua Code:
  1. 3x !Aardvark\Options-Options.lua:18: unexpected symbol near 'local'

And lines 1-30 of my code:
Lua Code:
  1. local Aardvark = LibStub("AceAddon-3.0"):GetAddon("Aardvark")
  2. local L = LibStub("AceLocale-3.0"):GetLocale("Aardvark", false)
  3. local ldbIcon = LibStub("LibDBIcon-1.0")
  4.  
  5. local options = nil
  6. local db
  7. local exempt = {
  8.     -- always allow these addons to print to chat
  9.     ["!Aardvark"] = true,
  10.     ["!Swatter"] = true,
  11.     ["Ace3"] = true,
  12.     ["BugSack"] = true,
  13.     ["Bugger"] = true
  14. }
  15. local OptionsHandler = {} -- local function to this file
  16.  
  17. local AddOnList = {
  18.     local list = {}
  19.     for i = 1, GetNumAddOns() do
  20.         local folderName, title = GetAddOnInfo(i)
  21.         if not exempt[folderName] then
  22.             local index = #list + 1
  23.             list[index] = title
  24.         end
  25.     end
  26.     table.sort(list, function(a, b) -- sort alphabetically
  27.         return a.name > b.name
  28.     end)
  29.     return list
  30. }
  Reply With Quote
11-02-18, 08:01 PM   #2
Terenna
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 105
AddOnList.list ={}
list = AddOnList.list

I don't think you can make a local table inside of a table with the syntax you've used.
  Reply With Quote
11-02-18, 08:54 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Assuming you wans list as a table in AddOnList otherwise, remove the AddOnList references.
Lua Code:
  1. local AddOnList = { list={} }
  2. for i = 1, GetNumAddOns() do
  3.     local folderName, title = GetAddOnInfo(i)
  4.     if not exempt[folderName] then
  5.         tinsert(AddOnList.list, {name=title} )
  6.     end
  7. end
  8. table.sort(AddOnList.list, function(a, b) -- sort alphabetically
  9.     return a.name > b.name
  10. end)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 11-02-18 at 08:59 PM.
  Reply With Quote
11-02-18, 10:25 PM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Ah ha. Here's my entire code. I'll load into game shortly to test. After line adjustments, I am trying to populate line 186 with the values contained in AddOnList. I don't need a table inside a table. I'm not sure if the do/end loop is necessary; I just put it there in case.
Lua Code:
  1. local Aardvark = LibStub("AceAddon-3.0"):GetAddon("Aardvark")
  2. local L = LibStub("AceLocale-3.0"):GetLocale("Aardvark", false)
  3. local ldbIcon = LibStub("LibDBIcon-1.0")
  4.  
  5. local options = nil
  6. local db
  7. local exempt = {
  8.     -- always allow these addons to print to chat
  9.     ["!Aardvark"] = true,
  10.     ["!Swatter"] = true,
  11.     ["Ace3"] = true,
  12.     ["BugSack"] = true,
  13.     ["Bugger"] = true
  14. }
  15. local OptionsHandler = {} -- local function to this file
  16. do
  17.     local AddOnList = {}
  18.     for i = 1, GetNumAddOns() do
  19.         local folderName, title = GetAddOnInfo(i)
  20.         if not exempt[folderName] then
  21.             table.insert(AddOnList, {name = title})
  22.         end
  23.     end
  24.     table.sort(AddOnList, function(a, b) -- sort alphabetically
  25.         return a.name > b.name
  26.     end)
  27. end
  28.  
  29. function Aardvark:GetOptions()
  30.     db = db or self.db.global
  31.     options = options or {
  32.         type = "group",
  33.         childGroups = "tab",
  34.         name = Aardvark.Name,
  35.         desc = Aardvark.Notes,
  36.         arg = "!Aardvark",
  37.         args = {
  38.             general = {
  39.                 order = 10,
  40.                 name = COMPACT_UNIT_FRAME_PROFILE_SUBTYPE_ALL,
  41.                 type = "group",
  42.                 args = {
  43.                     enable = {
  44.                         order = 10,
  45.                         name = ENABLE,
  46.                         desc = L["Toggle Aardvark on or off."],
  47.                         type = "toggle",
  48.                         get = function() return db.enabled end,
  49.                         set = function(info, value)
  50.                             db.enabled = value
  51.                             if value then
  52.                                 self:OnEnable()
  53.                             else
  54.                                 self:OnDisable()
  55.                             end
  56.                         end
  57.                     }, -- end enabled
  58.                     instance = {
  59.                         order = 20,
  60.                         name = L["Instance Chat"],
  61.                         desc = L["Leave General chat channel when you enter an instance, rejoin when you leave."],
  62.                         type = "toggle",
  63.                         get = function() return db.instance end,
  64.                         set = function(info, value)
  65.                             db.instance = value
  66.                             self:PLAYER_ENTERING_WORLD()
  67.                         end
  68.                     }, -- end instance General join/leave
  69.                     cleanChat = {
  70.                         order = 30,
  71.                         name = L["Clear Chat"],
  72.                         desc = L["Clear the chat windows when first logging in."],
  73.                         type = "toggle",
  74.                         get = function() return db.cleanChat end,
  75.                         set = function(info, value)
  76.                             db.cleanChat = value
  77.                         end
  78.                     }, -- end login clean chat
  79.                     saveGMOTD = {
  80.                         order = 40,
  81.                         name = GUILD_MOTD_LABEL2,
  82.                         desc = L["Restores guild message of the day after clearing chat when first logging in."],
  83.                         type = "toggle",
  84.                         disabled = function() return not db.cleanChat end,
  85.                         get = function() return db.saveGMOTD end,
  86.                         set = function(info, value)
  87.                             db.saveGMOTD = value
  88.                         end
  89.                     }, -- end GMOTD save
  90.                     cleanNow = {
  91.                         order = 50,
  92.                         name = L["Clean Chat Now"],
  93.                         type = "execute",
  94.                         width = "full",
  95.                         func = function() self:ClearChat() end,
  96.                         disabled = function() return not self.db.global.enabled end
  97.                     }, -- end clean now button
  98.                     hideLDBIcon = {
  99.                         order = 60,
  100.                         name = L["Hide Minimap Button"],
  101.                         desc = L["Toggle hiding the button"],
  102.                         type = "toggle",
  103.                         get = function() return db.minimap.hide end,
  104.                         set = function(info, value)
  105.                             db.minimap.hide = value
  106.                             if value then
  107.                                 ldbIcon:Hide("Aardvark")
  108.                             else
  109.                                 ldbIcon:Show("Aardvark")
  110.                             end
  111.                         end
  112.                     }, -- end toggle Broker button
  113.                     lockLDBIcon = {
  114.                         order = 70,
  115.                         name = L["Lock Button"],
  116.                         desc = L["Lock the button so it cannot be moved."],
  117.                         type = "toggle",
  118.                         get = function() return db.minimap.lock end,
  119.                         set = function(info, value)
  120.                             db.minimap.lock = value
  121.                             if value then
  122.                                 ldbIcon:Lock("Aardvark")
  123.                             else
  124.                                 ldbIcon:Unlock("Aardvark")
  125.                             end
  126.                         end
  127.                     }, -- end button lock
  128.                     minimapPos = {
  129.                         order = 80,
  130.                         name = L["Rotation"],
  131.                         desc = L["Rotate the button around the minimap."],
  132.                         type = "range",
  133.                         get = function() return db.minimap.minimapPos end,
  134.                         set = function(info, value)
  135.                             db.minimap.minimapPos = value
  136.                         end,
  137.                         disabled = function() return db.minimap.lock end,
  138.                         min = 1,
  139.                         max = 355,
  140.                         step = 1,
  141.                         bigStep = 5
  142.                     }, -- end of minimapPos
  143.                     radius = {
  144.                         order = 90,
  145.                         name = L["Range From Center"],
  146.                         desc = L["Move the button closer or further from the center of the minimap."],
  147.                         type = "range",
  148.                         get = function() return db.minimap.radius end,
  149.                         set = function(info, value)
  150.                             db.minimap.radius = value
  151.                         end,
  152.                         disabled = function() return db.minimap.lock end,
  153.                         min = 0,
  154.                         max = 160,
  155.                         step = 1,
  156.                         bigStep = 5
  157.                     } -- end of radius
  158.                 }
  159.             }, -- end of general options
  160.             addons = {
  161.                 order = 20,
  162.                 name = ADDONS,
  163.                 desc = L["Toggle AddOns' ability to send messages to the chat frame."],
  164.                 type = "group",
  165.                 handler = OptionsHandler,
  166.                 args = {
  167.                     selectAll = {
  168.                         order = 1, -- want it first
  169.                         name = ENABLE_ALL_ADDONS,
  170.                         desc = L["Enable all AddOns to print to chat."],
  171.                         type = "execute",
  172.                         func = "SelectAll",
  173.                     }, -- end of select all
  174.                     selectNone = {
  175.                         order = 2, -- want it second
  176.                         name = DISABLE_ALL_ADDONS,
  177.                         desc = L["Disable all AddOns from printing to chat."],
  178.                         type = "execute",
  179.                         func = "SelectNone"
  180.                     }, -- end of selecting no addons
  181.                     installedAddOns = {
  182.                         order = 3, -- want this third
  183.                         name = L["Selected AddOns"],
  184.                         desc = L["Toggle these off to prevent individual AddOns from printing to chat."],
  185.                         type = "multiselect",
  186.                         values = AddOnList,
  187.                         get = GetState,
  188.                         set = SetState
  189.                     } -- end of installed addons
  190.                 }
  191.             } -- end of addons section
  192.         }
  193.     }
  194.     return options
  195. end
  196.  
  197. function OptionsHandler:SelectAll(info)
  198. end
  199.  
  200. function OptionsHandler:selectNone(info)
  201. end
  202.  
  203. function OptionsHandler:SetState(info, index, state)
  204. end
  205.  
  206. function OptionsHandler:GetState(info, index)
  207. end
  Reply With Quote
11-03-18, 12:30 AM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
I don't Ace so I don't know what format AddOnList is supposed to be in, I was going on the sort you were using which was on the key "name".
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
11-03-18, 07:38 AM   #6
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
You have to move the "local AddOnList = {}" outside the do...end block or the rest of your code won't be able to see it.
Code:
local AddOnList = {}
do
    for i = 1, GetNumAddOns() do
        local folderName, title = GetAddOnInfo(i)
        if not exempt[folderName] then
            table.insert(AddOnList, {name = title})
        end
    end
    table.sort(AddOnList, function(a, b) -- sort alphabetically
        return a.name > b.name
    end)
end
  Reply With Quote
11-03-18, 10:20 AM   #7
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by Fizzlemizz View Post
I don't Ace so I don't know what format AddOnList is supposed to be in, I was going on the sort you were using which was on the key "name".
In Ace, values = AddOnList is a table, and it looks like the key is a number and value in this case is a string (although it could be anything valid). In other words:
Code:
values = k, v
No worries that you don't use Ace; the good news in this case is that is tables, not a mysterious API.

I am looking at GatherMate2's returned table, which needs to be a lot more complex than what I am doing, largely because GM2's table has zone, expansion, and gathered item data. It is also a metatable, which might be useful in case data is added or removed (maybe, in my case, if the user toggled AddOns on/off).

For reference, in GM's options table, it has values = sortedFilter["Archaeology"] or values = sortedFilter["Treasure"] etc.

My addon is not a plugin for GatherMate; I am merely looking at its code for reference on how to populate a table (values) with a set of unknown quantities (I have no idea which addons the user has installed, or how many).

Below is code from GatherMate2. It is the return from values = blah in the options table.
Lua Code:
  1. -- Setup some storage arrays by db to sort node names and zones alphabetically
  2. local delocalizedZones = {}
  3. local denormalizedNames = {}
  4. local sortedFilter = setmetatable({}, {__index = function(t, k)
  5.     local new = {}
  6.     table.wipe(delocalizedZones)
  7.     if k == "zones" then
  8.         for index, zoneID in pairs(GatherMate.HBD:GetAllMapIDs()) do
  9.             local name = GatherMate:MapLocalize(zoneID)
  10.             new[name] = name
  11.             delocalizedZones[name] = zoneID
  12.         end
  13.     else
  14.         local map = GatherMate.nodeIDs[k]
  15.         for name in pairs(map) do
  16.             local idx = #new+1
  17.             new[idx] = name
  18.             denormalizedNames[name] = name
  19.         end
  20.         local expansion = GatherMate.nodeExpansion[k]
  21.         if expansion then
  22.             -- We only end up creating one function per tracked type anyway
  23.             table.sort(new, function(a, b)
  24.                 local mA, mB = expansion[map[a]], expansion[map[b]]
  25.                 if not mA or not mB or mA == mB then return map[a] > map[b]
  26.                 else return mA > mB end
  27.             end)
  28.         else
  29.             table.sort(new)
  30.         end
  31.     end
  32.     rawset(t, k, new)
  33.     return new
  34. end})
  Reply With Quote
11-03-18, 10:43 AM   #8
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
I see the confusion. GatherMate2 is using setmetatable() but you tried to put a block of code directly into a table.

GatherMate2:

local sortedFilter = setmetatable( object, metaTable )

You:

local AddOnList = { --[[ block of code ]] }
  Reply With Quote
11-03-18, 11:44 AM   #9
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I think I solved it with your hints, tips, and extra eyes. I'll trim out the extra code, so the line numbers won't line up, but it gets the point. I will know for sure next time I log in. The adjusted line 195 now reads
Code:
values = function() return SortedAddOns(AddOnList) end,
Which calls the following chunk at the top of the file.
Lua Code:
  1. -- create a list of installed AddOns that are returned to the options table
  2. local AddOnList = {}
  3. local function SortedAddOns(AddOnList)
  4.     table.wipe(AddOnList) -- clean slate
  5.     for i = 1, GetNumAddOns() do
  6.         local folderName, title = GetAddOnInfo(i)
  7.         if not exempt[folderName] then -- ignore exempt addons
  8.             -- Lua tables start with an index of 1, and if AddOnList is empty, bump it to 1 instead of 0  for its first entry
  9.             local index = #AddOnList + 1
  10.             AddOnList[index] = title
  11.         end
  12.     end
  13.  
  14.     -- now sort AddOnList alphabetically
  15.     table.sort(AddOnList, function(a, b)
  16.         return a.name > b.name
  17.     end)
  18.  
  19.     -- return AddOnList to options
  20.     return AddOnList
  21. end

Last edited by myrroddin : 11-03-18 at 11:56 AM. Reason: syntax update for values =
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Need a second set of eyes to spot the error

Thread Tools
Display Modes

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