Page 1 of 1
[SOLVED]emptying a table completely
Posted: Mon Apr 18, 2016 7:48 pm
by Vimm
I want to remove every value thats in a table, but I can't figure out how, I tried making a variable that increments everytime something is added to the table, then making a for loop that, if the number of the object spawned is greater than or equal to 0, it removes 1 and decrements, then loops, heres the code I used
Code: Select all
for i, v in ipairs(listOfPillars) do
if numberOfPillars >= 0 then
table.remove(listOfPillars, 1)
numberOfPillars = numberOfPillars - 1
end
end
this, however, only seems to get rid of the first 2 pillars spawned, not all the ones on the screen :/ what am I missing? Am I even on the right track?
Re: emptying a table completely
Posted: Mon Apr 18, 2016 8:07 pm
by airstruck
The most straightforward way would be something like this (assuming you only use numeric indices):
Code: Select all
for i = 1, #listOfPillars do listOfPillars[i] = nil end
If you don't have too many references to that table floating around, you could just do
listOfPillars = {} and update any references.
Re: emptying a table completely
Posted: Mon Apr 18, 2016 8:17 pm
by Vimm
airstruck wrote:The most straightforward way would be something like this (assuming you only use numeric indices):
Code: Select all
for i = 1, #listOfPillars do listOfPillars[i] = nil end
If you don't have too many references to that table floating around, you could just do
listOfPillars = {} and update any references.
ayye that worked, thanks
geez im so bad with for loops and tables still
Re: emptying a table completely
Posted: Mon Apr 18, 2016 8:20 pm
by airstruck
Time to read PIL
Re: emptying a table completely
Posted: Mon Apr 18, 2016 8:29 pm
by Vimm
airstruck wrote:Time to read PIL
Haha I know I should but I just can't get around to it XD
How do I change the thread to solved?
Re: emptying a table completely
Posted: Mon Apr 18, 2016 8:33 pm
by zorg
Edit your first post, and put [Solved] before the subject.
Re: emptying a table completely
Posted: Mon Apr 18, 2016 9:10 pm
by Vimm
zorg wrote:Edit your first post, and put [Solved] before the subject.
witchcraft