WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   SavedVariables formatting (https://www.wowinterface.com/forums/showthread.php?t=58918)

NoxisAT 09-06-21 11:52 PM

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 :)

Fizzlemizz 09-07-21 12:19 AM

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)

NoxisAT 09-07-21 09:08 AM

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 :(

Fizzlemizz 09-07-21 10:54 AM

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.


All times are GMT -6. The time now is 07:58 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI