Thread Tools Display Modes
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
02/22/19, 12:58 PM   #2
Demiknight
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 4
Just a quick update on my question. I've still not found the code to correctly drop an item without causing an error. I did finally think about adding a row dynamically if needed.

if not (hideWorldXP and indexWorldXP == 0) then
o.Tools[_addon.G.BAR_TOOL_SpecialWorldXPBar] = { Name = "creature_xp_bar_enabled", Control = nil }
end

So, don't add the item by default, then add when needed. It's better than what I had, though I wish I understood why removal wasn't working.
  Reply With Quote
02/22/19, 01:25 PM   #3
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
You're certain there isn't a hardcoded reference to _addon.G.BAR_TOOL_BACKPACK somewhere else in the code? If there is, then it'll try to do whatever with it, but realize it's nil and break. If that's the case, you need to add a nil check on it at that point.
  Reply With Quote
02/22/19, 02:10 PM   #4
Demiknight
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 4
My assumption, which could obviously be very wrong, is that having the list with the row commented out causes no error. End result is what I want. However, setting the item to nil isn't the same as the item not having existed in the first place. So I sort of expect I could do what I want to do.

Most of the addon code is not mine... so your right, it's likely be a referencing something else. Perhaps rather than simply removing the array item it's nil'ing the widget control. One of the many challenge of trying to unravel addons from the olden days.

I'd kill for a solid debugger. Thanks
  Reply With Quote
04/09/19, 10:46 PM   #5
calia1120
 
calia1120's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 62
Silly Demi.... remember the Framework.......
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » Remove Item From List

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