Quantcast WoWInterface - View Single Post - Removing a table key?
View Single Post
09-09-14, 07:34 AM   #1
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,739
Removing a table key?

Assuming I want to save guids. At some point in the future I want to remove outdated guids.

Lua Code:
  1. local guids = {}
  2.  
  3. local guidA = "12345"
  4. local guidB = "ABCDE"
  5.  
  6. guids[guidA] = { time=time(), hp=UnitHealth(guidA) }
  7. guids[guidB] = { time=time(), hp=UnitHealth(guidB) }
*edit* Just found what I was looking for in the last sentence.

Note that table.remove only works with numeric indexes. For dictionaries you can just unset tables entries with tablevariable["index"] = nil; http://lua-users.org/wiki/TableLibraryTutorial
So I guess I will do this
Lua Code:
  1. for k,v in ipairs(guids) do
  2.   if time()-3600 > v.time then
  3.     guids[k] = nil
  4.   end
  5. end

Question. If I set the table value for a key to nil. When ipairs is called again. Will ipairs return keys with a value of nil?
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW) | TDMOG

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 09-09-14 at 07:46 AM.
  Reply With Quote