Removing Specific Subtables?

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.
User avatar
Dattorz
Citizen
Posts: 66
Joined: Sat Oct 27, 2012 12:32 am
Contact:

Re: Removing Specific Subtables?

Post by Dattorz »

You can't call a table (and doing this in Lua will cause you to receive an error). You're thinking of something different.

for i = #enemy - This is the initial statement of the for loop, declaring the initial value of i (#enemy means the total number of items in the enemy table). The 1 and -1 mean "Keep going through each value of the table with i being one less each time, until we get to 1."

See also: http://www.lua.org/pil/4.3.4.html
WolfNinja2 wrote:and enemy.remove is that just checking if v.remove is true?
Yes. Your objects will have a remove variable, initially set to false. Set it to true when you want to remove the object. This is because you don't want to actually remove the objects while you're still processing their logic (as this would cause a lot of problems). Instead, after running their logic you run through the list to see which objects need to be removed, and then remove those.
User avatar
Qcode
Party member
Posts: 170
Joined: Tue Jan 10, 2012 1:35 am

Re: Removing Specific Subtables?

Post by Qcode »

WolfNinja2 wrote: Sorry for being a nuisance ;/
It's always best to ask questions and understand the topic we're trying to teach you about, even if it does take lots of questions. That way you can learn how to do it yourself rather than coming back here all the time.
The code I was posting did what Dattorz said, but here's the reason why I was using the reverse loop. When you remove tables in a pairs loop there's a chance you can break the loop and stop things from properly being removed. That way you can always be sure the things are being fully removed from the table.
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Removing Specific Subtables?

Post by WolfNinja2 »

Thanks Guys but it is STILL not working :/ here is the game, to skip to the level where enemy's are, uncomment line 73 and comment in line 69 of main.lua :/

-Wolf
Attachments
enemy_troubles.love
(64.14 KiB) Downloaded 113 times
User avatar
Qcode
Party member
Posts: 170
Joined: Tue Jan 10, 2012 1:35 am

Re: Removing Specific Subtables?

Post by Qcode »

Don't know what you're talking about now. For me when you shoot the enemies they get removed. Is that not the intended effect, if so, what is?
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Removing Specific Subtables?

Post by WolfNinja2 »

Qcode wrote:Don't know what you're talking about now. For me when you shoot the enemies they get removed. Is that not the intended effect, if so, what is?
Oh....well maybe I should have tested more than once..... THANKS!!! :D
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 172 guests