[SOLVED]emptying a table completely

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

[SOLVED]emptying a table completely

Post 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?
Last edited by Vimm on Mon Apr 18, 2016 9:10 pm, edited 1 time in total.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: emptying a table completely

Post 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.
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: emptying a table completely

Post 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 :D

geez im so bad with for loops and tables still :death:
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: emptying a table completely

Post by airstruck »

Time to read PIL ;)
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: emptying a table completely

Post 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?
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: emptying a table completely

Post by zorg »

Edit your first post, and put [Solved] before the subject.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: emptying a table completely

Post by Vimm »

zorg wrote:Edit your first post, and put [Solved] before the subject.
:o witchcraft
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 199 guests