Jump to content

Table question


Karuzo

Recommended Posts

Hey Guys,

How can i remove/delete datas in a table if i have named my tables with strings and not with numbers like:

dxElements.statisticsgrid.player.veh 

So my question is can i remove everything which is in that dxElements.statisticsgrid.player table in a for-loop ?

like:

  
for i,v in ipairs(dxElements.statisticsgrid.player) do  
      dxElements.statisticsgrid.player.i = nil 
end 
  

^This will only work if i would use numbers and not strings, so what can i do ?

Link to comment

It's because you used ipairs which is used for ordering ( integers ) If you loop with pairs then it will work.

EDIT:

  
local a = { ["a"] = "foo" } 
for i, v in pairs (a) do 
print (a.i) --> "foo" 
a.i = nil 
print (a.i) --> nil 
end  

  
local a = { ["a"] = "foo" } 
for i, v in ipairs (a) do 
print (a.i) --> doesn't print anything cause ipairs is for integers key 
end  

Edited by Guest
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...