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
Having a problem with a 'table[i] = nil'
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 3
- Joined: Thu Jul 16, 2020 7:09 am
Having a problem with a 'table[i] = nil'
- Attachments
-
- main.lua
- (492 Bytes) Downloaded 86 times
Re: Having a problem with a 'table[i] = nil'
Too many problems to tackle at once. To start things off:
#1. Where's your function distanceBetween()? The error is looking for it. You might need to require it first.
#2. zombies.draw() seems to be one of the values in your zombies table. But I can't be sure yet.
#3. Replace zombies = nil with table.remove(zombies, i).
#1. Where's your function distanceBetween()? The error is looking for it. You might need to require it first.
#2. zombies.draw() seems to be one of the values in your zombies table. But I can't be sure yet.
#3. Replace zombies = nil with table.remove(zombies, i).
Re: Having a problem with a 'table[i] = nil'
Please also use [code]...[/code] tags to post code. Out of a code block, the [i] tag stands for italic, and your original line
now appears as zombies = nil
and makes the rest of your post italics.
Code: Select all
zombies[i] = nil
and makes the rest of your post italics.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 7 guests