Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:Creating defaults
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Advanced Default Setting Updating == Having worked with this for so long now, I've developed even more advanced methods for using these defaults. The first thing I've done is seperated the update code from the loading code, so it is it's own function. Another change I've made is that it can now work with tables within tables. The following can work with up to 3 levels of tables within your defaults. (Main level, 1 subtable, and a subtable within that.) You will also notice that if the version you are upgrading from is below or equal to version 1.2, then an error message will be displayed using a custom message display function. (Which I won't get into here.) This is useful if you've made major database changes and don't feel like making an adaptor for the settings. A common use of this would be if you had a lot of settings, but decided to move them into a subtable. This would ensure the old settings were erased. This functionality should be used sparingly. function ThisAddon_OptionUpdate() local temp = ThisAddon_Defaults["Options"]; if (ThisAddon_Settings["Version"]) and (ThisAddon_Settings["Version"] <= "1.2") then ThisAddon_Error_Msg("Your Database is Severely out of date. Some settings may not have carried over."); else for k,v in pairs(ThisAddon_Settings) do if (type(ThisAddon_Settings[k]) == "table") then for k2,v2 in pairs(ThisAddon_Settings[k]) do if (type(ThisAddon_Settings[k][k2]) == "table") then for k3,v3 in pairs(ThisAddon_Settings[k][k2]) do if (ThisAddon_Settings[k][k2][k3]) then temp[k][k2][k3] = v3; end end else if (ThisAddon_Settings[k][k2]) then temp[k][k2] = v2; end end end else if (ThisAddon_Settings[k]) then temp[k] = v; end end end end temp["Version"] = ThisAddon_Version; ThisAddon_Settings = {}; ThisAddon_Settings = temp; end Now let's go through this; *The function's name. ** Copy the new defaults into a temp variable. ** Here is the detection of an out-of-date database that can't be updated like normal. Will only fire if it detects an old version. *** What to do if it's out of date. (Send an error message so they know!) ** Otherwise... *** For every variable in your current settings... **** If it's a table... ***** Now we run through the subtable. ****** If it's a table... ******* You get the idea. (This function is repeated for the 2nd subtable.) ****** If it's not a table... ******* If the setting exists... ******** Update it! ***** End subtable. **** If it's not a table... ***** If the setting exists... ****** Update it! ** Update the temp var's Version number. ** Delete all the old settings. Technically, we shouldn't have to do with our next command, but this ensures that the old settings are deleted first. ** Copy the temp variable into our settings. * End function That's the basics of this new setting. The best thing is, now in our Post-Load function, instead of writing all that out, we just call: if (not ThisAddon_Settings["Version"]) or (ThisAddon_Settings["Version"] < ThisAddon_Version) then ThisAddon_OptionUpdate(); end Now you can do even more with defaults! If you come up with something new and original, put it on this HowTo's Discussion page! I'd love to see how people use this! [[Category:HOWTOs|Create Defaults]]
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)