View Single Post
02/22/19, 12:03 PM   #1
Demiknight
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 4
Remove Item From List

Making updates to the Wykk Toolbar addon and I've hit a situation that isn't making any sense. In the code there is a array that stores a list of toolbar items:

o.Tools = {
[_addon.G.BAR_TOOL_BACKPACK] = { Name = "bag_setting", Control = nil },
[_addon.G.BAR_TOOL_BANK] = { Name = "bank_setting", Control = nil },
...
[_addon.G.BAR_DURABILITY] = { Name = "durability_enabled", Control = nil },
[_addon.G.BAR_WEAPONCHARGE] = { Name = "weaponcharge_enabled", Control = nil },
}

The list is hard coded and I'd like to conditionally remove an item from the list. I tried

o.Tools[_addon.G.BAR_TOOL_BACKPACK] = nil

However, that gives me an error when the array is processed that a nil value exists. I also looked at using table.remove(), but that also didn't seem to work. Right now I'm only trying to remove one item from the list... so I made an if/else block building the hard coded list either with or without the item. That works, but...

a) From a maintainability point of view it poor. Who will remember to add anything new to both blocks.
b) Clearly coding two separate lists works, so there should be a way to actually remove the undesired element from the array. (Like it never existed in the first place.)

What am I missing here? Thanks.
  Reply With Quote