Error main.lua:52: attempt to get length of global 'zombies' (a nil value)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ZackGaming101
Prole
Posts: 5
Joined: Mon Aug 31, 2020 3:05 am

Error main.lua:52: attempt to get length of global 'zombies' (a nil value)

Post by ZackGaming101 »

Hi so I have had problems making this zombie game and I have a particular error which is the title of this comment you could call it. I have been stuck for a long time and I was wondering if anyone could solve the mistake I will drop both of the files in here. they are both .lua I just compressed them
Error main.lua:52: attempt to get length of global 'zombies' (a nil value) was the error
Attachments
main.lua
(1.46 KiB) Downloaded 164 times
collision.lua
(157 Bytes) Downloaded 193 times
MrFariator
Party member
Posts: 543
Joined: Wed Oct 05, 2016 11:53 am

Re: Error main.lua:52: attempt to get length of global 'zombies' (a nil value)

Post by MrFariator »

As it says, on line 52 of main.lua, you're trying to get the length of a nil value. This most commonly means a typo, or an undeclared variable. At closer inspection, on line 52 you write "zombies", and in love.load you only declare a table called "zombie". Glancing at the rest of the code, you seem to pick and choose between "zombie" and "zombies" at random (ex: lines 31 and 32) to refer to the aforementioned table.

Lua (and basically all other languages) will not make any assumptions for you, so you should pick one spelling and stick with it. Considering it's a table that should contain all the zombies, you probably want the globally accessible table to be called "zombies".
ZackGaming101
Prole
Posts: 5
Joined: Mon Aug 31, 2020 3:05 am

Re: Error main.lua:52: attempt to get length of global 'zombies' (a nil value)

Post by ZackGaming101 »

Yes thankk you very much @MrFariator. The reason i had zombies and zombie is because i needed to spawn in other "zombies" so now if i take away all the s from zombies i wouldnt get any to spawn. I don't know how to add zombies to my game i have the images and sounds. Im a beginner and do you have any advice on how to spawn in zombies and allow the player to also shoot them that would be very helpful. Thank you very much
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests