View Single Post
06-15-21, 05:33 PM   #1
Srzm
A Murloc Raider
Join Date: Jun 2021
Posts: 4
Saved Variables DB with a subtable: weird behaviour

Hey guys,

while developing my first greater AddOn I had several issues that I could fix myself. However, after research and testing I just can't get to the bottom of the following problem regarding some weird behaviour of a database subtable from SavedVariables. Hope you can help. And sorry for the incoming wall of text.

tl;dr: the full code is posted below.

I'm building a Config Dialog for my addon with AceConfigDialog and AceDBOptions. So far, everything works. My SavedVariables Database is listed in my .toc file . Lets say it's called addondb.

One part of addondb is a table with several subtables, containing stats a specific class + role should not have. It looks like this:

Code:
addondb = {
   failstats = {
      ["WARRIOR"] = {
         ["Arms"] = {"INT, "SPI", "SPW", "MP5","DEF","DDG","PAR","RES"}
      }
   }
}
And so on for every specc and class. You get the idea.
Those "failstats" are predefined (my research, several guides etc.). I want the player to have the option to change them the way he wants with a multiline input textbox. Here is the idea:



The multiline-input field get function. My code
- gets the failstats from the addondb["WARRIOR"]["Arms"] table,
- translates them into understandable stats ("INT" becomes "Intellect", as you see) and
- creates this multiline output by concatenating the stats with a newline "\n" in between.

Now to the set function of my input field. The set function
- splits the content of the input field at the "\n" newlines into a table "rawInput",
- removes wrong inputs like "bla bla bla",
- retranslates the understandable stats back into the shortened version and
- after all that, the addondb["WARRIOR"]["Arms"] table gets overwritten.

For clarification, the overwrite happens like this:

Code:
wipe(addondb.["WARRIOR"]["Arms"])
addondb.["WARRIOR"]["Arms"] = CopyTable(rawInput)
Up to this point, everything works perfectly fine. And here comes the tricky part, where weird behaviour happens.

See the above picture I posted. When I delete the last element ("Resilience Rating" here) from the input field, everything works out just well. I printed the final content of the subtables of "rawInput" and "addondb" via

Code:
table.foreach("tableName",print)
and it shows, that addondb["WARRIOR"]["Arms"] now has correctly "RES" (= "Resilience Rating", as you might guess) removed. However, reloading or restarting the game does not safe this at all. In fact, there is no change shown in the WTF/.../SavedVariables/.lua file as well.

And it gets even more weird. When I delete "Parry Rating", then again, before reloading or exiting the game, my debug prints show, that "PAR" has been successfully removed from the addondb table. But when reloading the game or exiting, the following gets saved in my WTF/.../SavedVariables/.lua file:

Code:
["failstats"] = {
   ["WARRIOR"] = {
      ["Arms"] = {
         [7] = "RES",
      }
   }
}
And now the text input field shows indeed, that the 7th element isn't "Parry Rating" anymore. It's "Resilience Rating". However, there is still the 8th element, former "Resilience Rating". This did not get deleted. Here a picture of this:



tl;dr. In conclusion, long stories short. It seems like the game only saves changes from the default settings in my table, but missing elements just get auto-filled with defaults? Am I missing something regarding table handling in the SavedVariables database?

I hope you got the idea of my code without me posting everything. Any basic ideas on what WoW does to my subtable when reloading? And why it does this weird stuff?

Here are a few more things regarding variables that get loaded. Maybe this helps.
In my .toc-file, I load everything in this order:

1. embeds.xml (embeding the Ace Libraries)
2. profiles.lua (containing the definition of the default settings)
3. Data.lua (containing global addon data, like dictionaries to translate between shorts to long stats, e.g. "INT" -> "Intellect")
4. config.lua (where actually my config dialog gets build)
5. Core.lua (with all the important stuff for my addon)

Thanks for any help. Have a great week!
Srzm

Last edited by Srzm : 06-15-21 at 06:20 PM.
  Reply With Quote