Page 1 of 1
Error main.lua:52: attempt to get length of global 'zombies' (a nil value)
Posted: Mon Aug 31, 2020 2:57 pm
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
Re: Error main.lua:52: attempt to get length of global 'zombies' (a nil value)
Posted: Mon Aug 31, 2020 4:16 pm
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".
Re: Error main.lua:52: attempt to get length of global 'zombies' (a nil value)
Posted: Mon Aug 31, 2020 6:48 pm
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