View Single Post
Unread 12-17-12, 01:06 PM   #3
gmarco
Premium Member
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 97
Hi Phanx,

As usual thanks for the reply.

Lua Code:
  1. function RemGank_Record_Player(name, note) 
  2.  
  3.     if note == nil or note == "" then  note = default_note end
  4.    
  5.     -- Define the new row in the array
  6.     RemGankDB[name] = RemGankDB[name] or {}
  7.    
  8.     -- not mandatory to be initialized anymore.
  9.     -- RemGankDB[name]["name"] = RemGankDB[name]["name"] or {}
  10.     -- RemGankDB[name]["desc"] = RemGankDB[name]["desc"] or {}
  11.     -- RemGankDB[name]["lastloc"] = RemGankDB[name]["lastloc"] or {}
  12.    
  13.     -- To prevent the math err on the sum of ( nil + 1 ) below
  14.     RemGankDB[name]["nrkill"] = RemGankDB[name]["nrkill"] or 0
  15.  
  16.     RemGankDB[name]["name"] = name:lower()
  17.     RemGankDB[name]["desc"] = string.sub(note,1,25)
  18.     RemGankDB[name]["lastloc"] = GetZoneText() .. "/" .. GetSubZoneText() .. " - " .. date("%d.%m.%Y %H:%M:%S")
  19.     RemGankDB[name]["nrkill"] = ( RemGankDB[name]["nrkill"] + 1 )  
  20.    
  21.     print(string_format("%s: adding %s [ %s ] [ kills: %i ] ", prgname, name, note, RemGankDB[name]["nrkill"]))
  22.    
  23. 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:
  1. if event == "ADDON_LOADED" and arg1 == "Remgank" then
  2.        
  3.         --- other code
  4.  
  5.         for name in pairs(RemGankDB) do
  6.             RemGankDB[name] = RemGankDB[name]
  7.         end
  8.     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.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
gmarco is offline   Reply With Quote