[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:
The following methods were tried to delete the table item Lua Code:
Lua Code:
Lua Code:
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? |
Without your real code it's not really possible to help.
It looks like you don't use the db but a local copy of it. |
Ah, good call.
This is my initialization code Lua Code:
The function that handles removing an item from the table is located in a different file Lua Code:
It's strange, though. Any changes go through no problem, but deleting part of a table doesn't. |
I'm not sure but iirc tremove does not trigger the metatable of the db-object.
Edit: Perhaps this thread can help you? https://authors.curseforge.com/forum...s-why-immortal The part with default entries that cant be deleted. Edit2: Or this http://lua-users.org/lists/lua-l/2008-07/msg00100.html |
I also tried these methods in place of tremove(), but still no luck :/
Edit: I just saw your edits and will check them out Edit2: Hmm, great find! I might have to add the values to the table on load, or something. -- Method #1 Lua Code:
|
You can't use an array like that. You want to use a dictionary:
Code:
groups = { Then to remove it you would do: Code:
groups[1]["LavaBurst"] = false I would suggest posting all of your code because it looks like you could make your options more efficient. |
Not to worry, the rest of my tables in my defaults are dictonaries. The reason I used an indexed table was that I needed the spells in a specific order, which you can't do with dictionaries. However, the solution I used was making a small addition to my "spells" table.
Original configuration Lua Code:
New configuration Lua Code:
Thanks for the help/insights, everyone :) |
If the array was necessary then all you needed to do with your original code was add a false at the end after removing the value. You were taking a table of length 5 and making it length 4 but the defaults were still length 5 so it added the default at the nil location. If AceDB sees a nil in your table when there is a value in that same spot in the defaults it puts the default value in, hence fill with false.
|
That wouldn't have worked with how my addon works because I've designed it so users can move spells between groups. The new method I coded works perfectly.
|
All times are GMT -6. The time now is 08:52 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI