Re: Why is table.remove making my program crash?
Posted: Fri Oct 28, 2011 9:50 pm
Not in this case - you have somewhat complicated the code, but still did not solve the problem Note that your magical whateverItIsYoureDoing() function could remove elements from mobs and/or ents table at the index lower than the current value of i, which would break your iteration.Taehl wrote:Argh, fine!miko wrote:So it was real 2-D problem, which can not (easily) be "linearized", like your case (in which there are no interactions between mobs and ents elements).The same basic method I presented still applies.Code: Select all
for i=math.max(#mobs, #ents), 1, -1 do local m,isDead = mobs[i] for i=#ents, 1, -1 do local e = ents[i] if whateverItIsYoureDoing then isDead = true table.remove(ents, i) end end if isDead then table.remove(mobs, i) end end
Try to change the code cited by ivan here:
http://love2d.org/forums/viewtopic.php? ... 841#p38800
Just remember that you need to check collisions between PlayerBullets[1] and Enemies[N], and also between PlayerBullets[M] and Enemies[1] (and every combination in between).