Page 1 of 1

Issue with Tables : Length returns nil

Posted: Tue Dec 23, 2014 10:22 am
by EmbeddedAlgorithm
I'm working on a shoot-em-up style game in Love and have run into an issue with Tables, when I try to add a bullet to my table of bullets the project errors and it says that the length of field is nil the problem seems to focus around this block of code. The problematic code is within a class written for a basic enemy (name the Slider).

The odd thing is that this implementation of a bullet style system works perfectly with my Player class and everything works perfectly.

Code: Select all

function slider:shoot(target_x, target_y)
	self.bullets[#self.bullets + 1] = {
		x = self.act_x,
		y = self.act_y,
		angle = math.atan2(target_y - self.act_y, target_x - self.act_x)
	}
end
Here is my Love file (as a side note, the classes are stored within the "lib" folder)-
ELIMINATE.love
(3.65 KiB) Downloaded 87 times
Thanks in advance and sorry for the bother, it's my first (proper) attempt at making a game in Love.

Re: Issue with Tables : Length returns nil

Posted: Tue Dec 23, 2014 10:45 am
by bartbes
The problem isn't in that function, it's where you call it. Look at lib/slider.lua line 32 again. Instead of calling shoot on self, you call it on 'slider', which indeed does not have a list of bullets. Replacing 'slider' with 'self' appears to fix the problem.

Re: Issue with Tables : Length returns nil

Posted: Tue Dec 23, 2014 8:26 pm
by EmbeddedAlgorithm
Wow, thanks. I had no idea I was referencing that wrong. Thanks again. :awesome: