I haven't programmed in a while and am already running into an error ... here is the code that isn't working.
Code: Select all
for i,v in ipairs(bullet) do
v.y = v.y + (bullet_speed * dt)
if v.y > w/2 then
table.remove(v)
end
end
Code: Select all
for i,v in ipairs(bullet) do
v.y = v.y + (bullet_speed * dt)
if v.y > w/2 then
table.remove(v)
end
end
Code: Select all
Let's say a table has 5 bullets. Here's what will happen if you remove all bullets.
1. Remove the first one (at this stage, i=1)
2. Loop through, increasing index by 1 (i=2)
3. This is where it will error: Remove the 2nd one.
Code: Select all
for i=#bullet, 1, -1 do
local v=bullet[i]
v.y = v.y + (bullet_speed * dt)
if v.y > w/2 then
table.remove(bullet, i)
end
end
Users browsing this forum: Bing [Bot] and 1 guest