function EffectUpdate(t)
if effectlist ~= nil then
for i=1,#effectlist do
effectlist[i].time = effectlist[i].time + t*400 -- problem is showing on this line
effectlist[i].y = effectlist[i].y - 1
if effectlist[i].time > effectlist[i].duration then
table.remove(effectlist, i)
end
end
end
end
description of the problem is this: if i attack the enemy fast the second or third damage gives a index nil problem.
I have no clue where to start solve this if someone can help i will appreciate.
You need to iterate the table backwards, when you table.remove the first effect but there were two effects then the second one gets moved to the first slot but you still enter the loop again with i=2.
function EffectUpdate(t)
if effectlist ~= nil then
for i = #effectlist, 1, -1 do
if effectlist[i].time > effectlist[i].duration then -- problem here index nil continues
table.remove(effectlist, i)
else
effectlist[i].time = effectlist[i].time + t*400
effectlist[i].y = effectlist[i].y - 1
end
end
end
end
but the problem persists in te same line
Last edited by tetsuken on Sat Aug 08, 2015 8:25 pm, edited 1 time in total.
function EffectUpdate(t)
if effectlist ~= nil then
for i = #effectlist, 1, -1 do
if effectlist[i] then
if effectlist[i].time > effectlist[i].duration then -- problem here index nil continues
table.remove(effectlist, i)
else
effectlist[i].time = effectlist[i].time + t*400
effectlist[i].y = effectlist[i].y - 1
end
end
end
end
end
You should be iterating backwards through the effectlist table since that's what you want to remove. Secondly, it's going to crash if it's trying to index a value which doesn't exist, hence why I suggest putting "if effectlist then".
if effectlist ~= nil then
for i = #effectlist, 1, -1 do -- i was make worng here using entitylist instead effectlist
if effectlist[i].time > effectlist[i].duration then
table.remove(effectlist, i)
else
effectlist[i].time = effectlist[i].time + t*400
effectlist[i].y = effectlist[i].y - 1
end
end
end