Having a problem with a 'table[i] = nil'
Posted: Thu Jul 16, 2020 7:20 am
Hello my name is Wilson, as of right now I'm having a problem with my code that I cant wrap my head around. I"m very new to love2d and I bought a class from udemy (heres the link to it: https://www.udemy.com/course/lua-love/). The problem I'm facing is where I have a for loop inside of table. Im not sure if its considering the entire function 'nil' or the draw function 'nil.
It's giving me an error output whenever the player makes contact with the zombie:
function zombies.draw()
--assigns an iterations to how many zombies spawn
for i, z in ipairs(zombies) do
z.x = z.x - math.cos(zombies.angle(z))
z.y = z.y - math.sin(zombies.angle(z))
love.graphics.draw(Sprites.zombies, z.x, z.y, zombies.angle(z), 1.5, 1.5, Sprites.zombies:getWidth()/2, Sprites.zombies:getHeight()/2)
if distanceBetween(z.x, z.y, player.x, player.y) < 100 then
for i, z in pairs(zombies) do
zombies = nil
end
end
end
end
zombie.lua:20: attempt to call global 'distanceBetween' (a nil value)
I'll leave my entire code in the description (the main problem is zombie.lua). Thank you in advance
It's giving me an error output whenever the player makes contact with the zombie:
function zombies.draw()
--assigns an iterations to how many zombies spawn
for i, z in ipairs(zombies) do
z.x = z.x - math.cos(zombies.angle(z))
z.y = z.y - math.sin(zombies.angle(z))
love.graphics.draw(Sprites.zombies, z.x, z.y, zombies.angle(z), 1.5, 1.5, Sprites.zombies:getWidth()/2, Sprites.zombies:getHeight()/2)
if distanceBetween(z.x, z.y, player.x, player.y) < 100 then
for i, z in pairs(zombies) do
zombies = nil
end
end
end
end
zombie.lua:20: attempt to call global 'distanceBetween' (a nil value)
I'll leave my entire code in the description (the main problem is zombie.lua). Thank you in advance