This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
jessechisel126's profile picture

How To Clear A Table

Started by jessechisel126, 26 July 2013 - 07:54 AM
jessechisel126 #1
Posted 26 July 2013 - 09:54 AM
I'm messing around with tables and am in need of a way to clear an already existing table. Being new to Lua, I can't figure out what to do at this point (Also, what I have already looks so hilariously wrong). Help would be appreciated.
LBPHacker #2
Posted 26 July 2013 - 09:58 AM
If you must keep using the reference the table points to, you'll have to nil every indices of the table:
for key, value in pairs(tbl) do tbl[key] = nil end
If you use the table only for one thing, and the reference is not important, you can just recreate it:
tbl = {}
EDIT: The latter creates a new table right there an then and puts its reference into tbl.
jessechisel126 #3
Posted 26 July 2013 - 10:17 AM
If you must keep using the reference the table points to, you'll have to nil every indices of the table:
for key, value in pairs(tbl) do tbl[key] = nil end
If you use the table only for one thing, and the reference is not important, you can just recreate it:
tbl = {}
EDIT: The latter creates a new table right there an then and puts its reference into tbl.

Can't believe I didn't think of those haha. Thanks again LBPHacker!