I have a table where i keep scores during the game and average them at the end of the game. As a new game is started I would like to clear this table and start fresh. Is there an easy way to do this or do I have to write a function to assign each value to nil? [import]uid: 8192 topic_id: 2247 reply_id: 302247[/import]
You could just create a new table. The old table will get garbage-collected, unless you have other references to it.
Matt
[import]uid: 78 topic_id: 2247 reply_id: 6782[/import]
Shall I just create a new table with the same name? I am really not sure about how the process works. If I store some scores in the table and then the game is over. When will the table be deleted? [import]uid: 8192 topic_id: 2247 reply_id: 6807[/import]
Hi,
I’m not sure about that one but it should work:
local myTable = {}
myTable[0] = 240
-- rest of your code
print(myTable[0]) -- should be 240
myTable = nil
print(myTable[0]) -- should be nil
myTable = {}
[import]uid: 8121 topic_id: 2247 reply_id: 6814[/import]
Ok. So as long as the table has nothing in it, it will be trashed. [import]uid: 8192 topic_id: 2247 reply_id: 6820[/import]
Removing a reference to the table will cause the content to go away (GC’d). Setting a table to “nil” or assigning a value to the variable is all that it takes.
-Tom [import]uid: 7559 topic_id: 2247 reply_id: 7052[/import]