It's off-by-one error:
arraySearch = 0
while arraySearch <= arrayLength do
arraySearch = arraySearch + 1
You run through the loop arrayLength+1
number of times, going through indexes 1..arrayLength+1
. You want to go through the loop only arrayLength
number of times with indexes 1..arrayLength
. The solution is to change the condition to arraySearch < arrayLength
.
Another (more Lua-ly way) is to write this as:
for arraySearch = 1, #objectArray do
Even more Lua-ly way is to use ipairs
and table.field
reference instead of (table["field"]
):
function refreshObjects()
for _, el in ipairs(objectArray) do
love.graphics.draw(el.renderimage, el.X, el.Y, movingLeft and 120 or 0)
end
end
objectArray
and movingLeft
should probably be passed as parameters...