Page 1 of 1

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

Posted: Sun Apr 19, 2015 3:08 pm
by Wrathguy78
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)

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

Posted: Sun Apr 19, 2015 3:27 pm
by Skeiks
You need to pass dt into the move function.

bullet.move(dt)

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

Posted: Sun Apr 19, 2015 3:34 pm
by Wrathguy78
Skeiks wrote:You need to pass dt into the move function.

bullet.move(dt)
Thank you!