Page 1 of 1

attempt to preform arithmetic on field "xvel" (a nil value)

Posted: Mon Mar 10, 2014 12:41 am
by Omnikariz
I'm getting this error in my player.lua, inside my player.physics(dt), and I'm not really sure how to fix this with the error.

Code: Select all

function player.physics(dt)
	player.x = player.x + player.xvel * dt
	player.y = player.y + player.yvel * dt
	player.xvel = player.xvel * (1 - math.min(dt*friction, 1))
end
I've gotten this error before and I really don't know at all what to do about it.

.LOVE For the game is attached, thanks in advance.

Re: attempt to preform arithmetic on field "xvel" (a nil val

Posted: Mon Mar 10, 2014 1:23 am
by micha
This error means that the variable player.xvel does not exist at the time when the corresponding line is executed. Add

Code: Select all

player.load()
to you love.load and the error is gone (you will get a different error then, because friction is not defined).

Re: attempt to preform arithmetic on field "xvel" (a nil val

Posted: Tue Mar 11, 2014 2:48 am
by Omnikariz
Yeah, thanks, shortly after posting this I found out the problems. Thanks anyway though.