I'd like to be able to make this function clear out the table, or overwrite it instead of adding onto it. How would I go about that? I couldn't just use table.remove(rolls)
could I?
sides = 6 numdice = 1 rolls{} function rollthedice() for i = 1, numdice do table.insert(rolls, math.random(1,sides)) end end
For many purposes, you can just replace the variable with a new empty table:
rolls = {}
This doesn't actually affect the old object, meaning if you had something like this:
local old_rolls = rolls rolls = {} print(#old_rolls) --> 5 or whatever
the ones referencing the old table won't be cleared. Normally you shouldn't have that case.
If you have a list, you can repeatedly table.remove
from it:
while #rolls > 0 do table.remove(rolls) end