View Single Post
08-08-18, 11:14 PM   #1
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
[SOLVED] Help with AceDb: Deleting items from table won't stay deleted.

I'm currently at a loss with this and have tried many different things to no avail, including searching google

To quickly explain what's going on, I'm trying to delete an item from a specific table in my addon's db - that uses AceDb - and it works, but the deletion is reverted when the game/ui is reloaded.

The table below is the table I've been working with to test. In my addon's config, I've coded the ability to remove spells from the group. In my case, I've been trying to remove item #3, "LavaBurst".
Lua Code:
  1. groups = {
  2.     [1] = {
  3.         [1] = "FlameShock",
  4.         [2] = "EarthShock",
  5.         [3] = "LavaBurst",
  6.         [4] = "Earthquake",
  7.         [5] = "ElementalBlast",
  8.     },
  9.     ...
  10. },

The following methods were tried to delete the table item
Lua Code:
  1. -- Tried the simplest way to remove a table item
  2. tremove(db.auras[spec].groups[grp],j)

Lua Code:
  1. -- Tried an advance means of removing a table item
  2. local function RemoveItemFromTable(db,index)
  3.     local numItems = #db
  4.    
  5.     db[index] = nil
  6.    
  7.     if (index < numItems) then
  8.         for i=index,numItems do
  9.             if (db[i + 1]) then
  10.                 db[i] = db[i + 1]
  11.                 db[i + 1] = nil
  12.             else
  13.                 db[numItems] = nil
  14.             end
  15.         end
  16.     end
  17. end

Lua Code:
  1. -- I even tried clearing that table completely and rebuilding it
  2. local function RebuildAuraGroupTable(db,grp)
  3.     local tempTable = {}
  4.    
  5.     for i=1,#db[grp] do
  6.         tinsert(tempTable,db[grp][i])
  7.     end
  8.    
  9.     db[grp] = nil
  10.    
  11.     db[grp] = {}
  12.    
  13.     for i=1,#tempTable do
  14.         db[grp][i] = tempTable[i]
  15.     end
  16. end
Using LuaBrowser, I can verify that "LavaBurst" is correctly removed from the table.

BEFORE DELETION


AFTER DELETION (Before game/UI reload)


AFTER DELETION (After game/UI reload)


It's clear that AceDb didn't recognize the deletion and is just loading slot #5 from the "defaults" table on reload. Is there any way to stop this from happening?

Last edited by Sweetsour : 08-09-18 at 10:43 AM.
  Reply With Quote