ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   AddOn Help/Support (https://www.esoui.com/forums/forumdisplay.php?f=164)
-   -   Remove Item From List (https://www.esoui.com/forums/showthread.php?t=8360)

Demiknight 02/22/19 12:03 PM

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.

Demiknight 02/22/19 12:58 PM

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.

Rhyono 02/22/19 01:25 PM

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.

Demiknight 02/22/19 02:10 PM

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

calia1120 04/09/19 10:46 PM

Silly Demi.... remember the Framework.......


All times are GMT -6. The time now is 01:26 AM.

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