Clear table

Hello,

i have a question about tables and arrays: what the most effective way to clear everything( i.e reset) from table or array? Can anyone show me an example, please?

any help is appreciated [import]uid: 16142 topic_id: 17784 reply_id: 317784[/import]

If you want to clear everything from the table? Use:

t = {}[/code]That's if you're just storing variables though. If you have references to other display objects, you'll want to iterate through the table and remove them individually.Here's a tutorial that fully goes over the use of tables in Corona:http://blog.anscamobile.com/2011/06/understanding-lua-tables-in-corona-sdk/ [import]uid: 52430 topic_id: 17784 reply_id: 67845[/import]

thanks, although i already have understanding of tables and know how to clear them, but wanted to ask opinions) [import]uid: 16142 topic_id: 17784 reply_id: 67898[/import]

I use a for loop to iterate through the table. This only works for tables with a numeric key.

[lua]local table = {}

for i=1, #table do
table[i]:removeSelf() – Optional Display Object Removal
table[i] = nil – Nil Out Table Instance
end[/lua]

Hope this helps :slight_smile: [import]uid: 53766 topic_id: 17784 reply_id: 67904[/import]