Hi Phanx,
As usual thanks for the reply.
Lua Code:
function RemGank_Record_Player(name, note)
if note == nil or note == "" then note = default_note end
-- Define the new row in the array
RemGankDB[name] = RemGankDB[name] or {}
-- not mandatory to be initialized anymore.
-- RemGankDB[name]["name"] = RemGankDB[name]["name"] or {}
-- RemGankDB[name]["desc"] = RemGankDB[name]["desc"] or {}
-- RemGankDB[name]["lastloc"] = RemGankDB[name]["lastloc"] or {}
-- To prevent the math err on the sum of ( nil + 1 ) below
RemGankDB[name]["nrkill"] = RemGankDB[name]["nrkill"] or 0
RemGankDB[name]["name"] = name:lower()
RemGankDB[name]["desc"] = string.sub(note,1,25)
RemGankDB[name]["lastloc"] = GetZoneText() .. "/" .. GetSubZoneText() .. " - " .. date("%d.%m.%Y %H:%M:%S")
RemGankDB[name]["nrkill"] = ( RemGankDB[name]["nrkill"] + 1 )
print(string_format("%s: adding %s [ %s ] [ kills: %i ] ", prgname, name, note, RemGankDB[name]["nrkill"]))
end
Studying better my code I finally realized that I don't need the commented out part.
The line 6 is mandatory as you explained me some messages ago :-) and the 14 is to prevent a math error when trying to add a nil + 1 few lines after.
Better yet, you should just validate your DB once when your addon loads, instead of every time you add a record.
|
This is the part I could not understand how to accomplish.
This because the only way I think I could do is something like :
Lua Code:
if event == "ADDON_LOADED" and arg1 == "Remgank" then
--- other code
for name in pairs(RemGankDB) do
RemGankDB[name] = RemGankDB[name]
end
end
But I have to add the same 2 lines (6 and 14 of the first sample) in the
RemGank_Record_Player to prevent an error when RemGankDB[name] is nil ( adding a new player not yet in the DB ) .
So I don't find any utility in use that for ... end in the ADDON_LOADED event.
I am sorry if this message is not so clear but it is not easy for me to explain better.
Thanks again for your time.