Thread Tools Display Modes
11-03-06, 02:25 AM   #1
Jayhawk
Premium Member
 
Jayhawk's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 105
Emptying DB keys

I'm trying to remove (partial) data from my saved variables. Say I have the following structure:

Code:
[topLevelKey] = {
    [subLevelKey01] = {
        value = foo
    }
    [subLevelKey02] = {
        value = foofoo
    }
    [subLevelKey02] = {
        value = foofoofoo
    }
}
And I want to remove the whole subLevelKey02 entry, so it ends up looking like:


Code:
[topLevelKey] = {
    [subLevelKey01] = {
        value = foo
    }
    [subLevelKey02] = {
        value = foofoofoo
    }
}
How do I do this?
I tried setting
Code:
self.db.profile.topLevelKey[subLevelKey02] = nil
But then it ends up like:

Code:
[topLevelKey] = {
    [subLevelKey01] = {
        value = foo
    }
    [subLevelKey02] = { }
    [subLevelKey02] = {
        value = foofoofoo
    }
}
Which doesn't quite cut the mustard.

Help?
  Reply With Quote
11-03-06, 03:12 PM   #2
sarf
A Cyclonian
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 47
Do it like this:
Code:
self.db.profile.topLevelKey.subLevelKey02 = nil
The reason it does not work is that using [] means "use the key value of the parameter specified inside the []s" so if you do the following:
Code:
a = {} a.b = 15; a.c = 2; a["d"] = a.b + a.c;
a.d will be 17 - and you can address it as a.d or a["d"] - it does not matter which.

Essentially, only use [] when you iterate through a table with an index key. Examples:
Code:
for k, v in pairs(defaults) do if ( settings[k] == nil ) then settings[k] = v; end
for i = 1, 40, 1 do raidUnitIds[i] = "raid"..i; end
Sarf
  Reply With Quote
11-04-06, 12:31 AM   #3
Jayhawk
Premium Member
 
Jayhawk's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 105
Ok... I get the theory, but I realise I still mis something.

My problem is that the keys are dynamic. I'm trying to do the following. My addon saves skill data per character. I want to be able to remove that data for a specific character, chosen from a list.

So.
TopLevelKey is the dataitem that keeps track of the skills.
SubLevelKey is a charactername ("realmName|toonName")

Currently I create a little pop out menu listing all characters (other than the current) in the same realm. Each dewdrop entry call a function
Code:
    'func', function() self:PurgeCharacterData(realmName..'|'..toonName) end
This function should do the purging. I've rewritten it similar to what you suggest but I got a feeling this won't work.

Code:
function SkillsPlusFu:PurgeCharacterData(toonSaveKey)
    self.db.profile.toonSave.toonSaveKey = nil
    self.db.profile.skillSave.toonSaveKey = nil
    self:Update()
end
I guess the error messages (invalida array index) on the second line and a zero effect on the savedvariable file even if I comment out that line are dead giveaways as to it not working.
  Reply With Quote
11-04-06, 02:21 AM   #4
wmrojer
A Deviate Faerie Dragon
 
wmrojer's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 13
Code:
table.remove(self.db.profile.topLevelKey,subLevelKey02)
  Reply With Quote
11-04-06, 02:42 AM   #5
Jayhawk
Premium Member
 
Jayhawk's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 105
I tried that, but that expects a numeric index in the table, rather than a string key.
  Reply With Quote
11-04-06, 03:38 AM   #6
Tekkub
A Molten Giant
 
Tekkub's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 960
AceDB provides per-char profiles, you don't need to manage it yourself....

self.db.char.whatever = "Whatever"
  Reply With Quote
11-04-06, 03:46 AM   #7
Jayhawk
Premium Member
 
Jayhawk's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 105
Hi Tekkub,
I'm not sure that's what I'm after.

The addon I wrote (SkillsPlus) makes it possible to view the skills of your other toons (so I can't put them in the db.char, and saves some data per character, (which I guess should go in the db.char. )

Anyroad, the point here being, that if you delete a character, the skills database still shows the skills for that toon. I'd like to purge that information, which seems a lot harder than I expected. I hope that made sense?
  Reply With Quote
11-04-06, 11:41 AM   #8
sarf
A Cyclonian
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 47
Change your fuction to this:
Code:
function SkillsPlusFu:PurgeCharacterData(toonSaveKey)
    self.db.profile.toonSave[toonSaveKey] = nil
    self.db.profile.skillSave[toonSaveKey] = nil
    self:Update()
end
You almost had it - there was just a minor confusion about tables - and believe me, I've been thrown for a spin in that department myself in Lua.

Essentially, table[] should mainly be used for dynamic keys (and keys with whitespace in it) and table. should ONLY be used with static keys. While you can do static access using [], you really shouldn't unless you have to (whitespace etc).

Sarf
  Reply With Quote
11-07-06, 06:20 AM   #9
Jayhawk
Premium Member
 
Jayhawk's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 105
Hi sarf
Thanks for the help. I actually tried that initially, but it didn't seem to work. I now found out something's wrong with the definition of the calling menu.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Emptying DB keys


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