Quantcast
SavedVariables formatting - WoWInterface
Thread Tools Display Modes
09-06-21, 11:52 PM   #1
NoxisAT
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jun 2021
Posts: 3
SavedVariables formatting

Hi,

this is my my Saved Variables now:
Lua Code:
  1. CRE_GuildRoster = {
  2.     {
  3.         ["Noxis"] = {
  4.             ["Class"] = "Priest",
  5.             ["Note"] = "Main",
  6.             ["Gilde"] = "Sometimes Prepared",
  7.             ["Level"] = 70,
  8.         },
  9.     }, -- [1]
  10. }

i want it to look like this i added the ["Players"] node

Lua Code:
  1. CRE_GuildRoster = {
  2.     ["Players"] ={
  3.         ["Noxis"] = {
  4.             ["Class"] = "Priest",
  5.             ["Note"] = "Main",
  6.             ["Gilde"] = "Sometimes Prepared",
  7.             ["Level"] = 70,
  8.         },
  9.     },
  10. }

this is my function:
Lua Code:
  1. local t = {}
  2. function CreateGRTable()
  3.    
  4.     wipe(t)
  5.     numTotal = GetNumGuildMembers();
  6.     for i = 1, numTotal do
  7.         name, rank, rankIndex, level, class, zone, note, officernote, online, status, classFileName, achievementPoints, achievementRank, isMobile, isSoREligible, standingID = GetGuildRosterInfo(i)
  8.         tinsert(t, i, {[Split(name, "-")[1]] = {Level = level, Gilde = guildName, Class = class, Note = officernote}})
  9.     end
  10.     CRE_GuildRoster[Players] = t
  11. end

can anyone explain me how to do this?
thanks
  Reply With Quote
09-07-21, 12:19 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,439
You could just change
Code:
CRE_GuildRoster = {
    {
to
Code:
CRE_GuildRoster = {
    ["Players"] = {
in the SavedVariables file (your addon will need to be ready for the change next login):

or for a an already distributed addon:
Lua Code:
  1. local function CopyTable(src, dest)
  2.     for index, value in pairs(src) do
  3.         if (type(value) == "table") then
  4.             dest[index] = {};
  5.             DL_Copy_Table(value, dest[index]);
  6.         else
  7.             dest[index] = value;
  8.         end
  9.     end
  10. end
  11.    
  12. CRE_GuildRoster.Players = {}
  13. CopyTable(CRE_GuildRoster[1], CRE_GuildRoster.Players)
  14. tremove(CRE_GuildRoster, 1)
That should copy all the entries from [1] to ["Players"] even if you have more entries than just ["Noxis"].

It doesn't account for having tables other than [1] with information to be transfered.

While testing, you could do the tremove(CRE_GuildRoster, 1) seperately after you've logged out and verified the information has been copied (make backups of your Saved Variables file first)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-07-21 at 12:35 AM.
  Reply With Quote
09-07-21, 09:08 AM   #3
NoxisAT
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jun 2021
Posts: 3
ok that worked thanks a lot

but is there a way to Serialize the Lua Table as Json?
i tried it with LibParse but its not working anymore
  Reply With Quote
09-07-21, 10:54 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,439
Not that I know of.

I imagine people might create an external process for parsing the SavedVariable file to something else rather than doing it in-game. It would all end up in the same place as SavedVariables are the only mechanism in WoW for addons to write to disk.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » SavedVariables formatting

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off