Attempt to perform arithmetic on local 'dt' 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
Wrathguy78
Prole
Posts: 10
Joined: Sun Jul 27, 2014 4:54 pm

Attempt to perform arithmetic on local 'dt' a nil value

Post by Wrathguy78 » Sun Apr 19, 2015 3:08 pm

So, I am trying to make a gun game and when I press right, left, up or down it is supposed to shoot a bullet, but I get that error! Heres the error:
bullet.lua:28: attempt to perform arithmetic on local 'dt' a nil value

Code: Select all

bullet = {}
bullet.width = 5
bullet.height = 5
bullet.speed = 500
function bullet.spawn(x,y,dir)
	table.insert(bullet, {x = x, y=y, dir = dir})
end

function bullet.draw()
	for i,v in ipairs(bullet) do
		love.graphics.setColor(0,0,255)
		love.graphics.rectangle('fill',v.x,v.y,bullet.width,bullet.height)
	end
end

function bullet.move(dt)
	for i,v in ipairs(bullet) do
		if v.dir == 'up' then
			v.y = v.y - bullet.speed * dt
			end
		if v.dir == 'down' then
			v.y = v.y + bullet.speed * dt
			end
		if v.dir == 'right' then
			v.x = v.x + bullet.speed * dt
			end
		if v.dir == 'left' then
			v.x = v.x - bullet.speed * dt
		end
	end
end

function DRAW_BULLET()
	bullet.draw()
end
function UPDATE_BULLET(dt)
	bullet.move()
end
(P.S It might be the bullet tutorial video i watched... I made the game myself i was having trouble with bullet)

User avatar
Skeiks
Citizen
Posts: 51
Joined: Wed Jan 28, 2015 1:51 pm

Re: Attempt to perform arithmetic on local 'dt' a nil value

Post by Skeiks » Sun Apr 19, 2015 3:27 pm

You need to pass dt into the move function.

bullet.move(dt)

Wrathguy78
Prole
Posts: 10
Joined: Sun Jul 27, 2014 4:54 pm

Re: Attempt to perform arithmetic on local 'dt' a nil value

Post by Wrathguy78 » Sun Apr 19, 2015 3:34 pm

Skeiks wrote:You need to pass dt into the move function.

bullet.move(dt)
Thank you!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], GVovkiv and 59 guests