Karuzo Posted August 15, 2014 Share Posted August 15, 2014 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
Bonsai Posted August 15, 2014 Share Posted August 15, 2014 As far as I know, you can delete everything by just doing: dxElements.statisticsgrid.player = {} Link to comment
#DRAGON!FIRE Posted August 15, 2014 Share Posted August 15, 2014 for ex .. : for _,v in ipairs ( table ) do v = nil end Link to comment
Saml1er Posted August 17, 2014 Share Posted August 17, 2014 This will work. Have you tested it? for i,v in ipairs(dxElements.statisticsgrid.player) do dxElements.statisticsgrid.player.i = nil end You can also use bons method. Link to comment
Karuzo Posted August 17, 2014 Author Share Posted August 17, 2014 For some reason your method didn't work,Saml1er. But Bonsais did. Thanks guys. Link to comment
Saml1er Posted August 17, 2014 Share Posted August 17, 2014 (edited) 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 August 17, 2014 by Guest Link to comment
DiSaMe Posted August 17, 2014 Share Posted August 17, 2014 some_table.i is the same as some_table["i"], not some_table Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now