Issue with Tables : Length returns nil

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
User avatar
EmbeddedAlgorithm
Prole
Posts: 2
Joined: Tue Dec 23, 2014 10:05 am

Issue with Tables : Length returns nil

Post 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 89 times
Thanks in advance and sorry for the bother, it's my first (proper) attempt at making a game in Love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Issue with Tables : Length returns nil

Post 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.
User avatar
EmbeddedAlgorithm
Prole
Posts: 2
Joined: Tue Dec 23, 2014 10:05 am

Re: Issue with Tables : Length returns nil

Post by EmbeddedAlgorithm »

Wow, thanks. I had no idea I was referencing that wrong. Thanks again. :awesome:
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests